1.forEach function
Both Firefox and Chrome's array types have a foreach function. Use the following:
<!--Add by oscar999--> <! DOCTYPE HTML Public"-//W3C//DTD HTML 4.0 transitional//en"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta name="Author"Content="oscar999"> </HEAD> <BODY> <script>varArryall = []; Arryall.push (1); Arryall.push (2); Arryall.push (3); Arryall.push (4); //Anonymous WayArryall.foreach (function (e) {alert (e); }) function T1 (ARG) {alert (arg);}//non-anonymous modeArryall.foreach (t1,arryall);</script> </BODY> </HTML>
HTML notation:
int 0 "'" + t+"'"; i++; })// non-JS notation, array elements plus fixed elements //ie not verified, 360, Firefox normal use
But the above, the code in IE does not work properly.
Because the IE array does not have a ForEach() method:
The implementation of the above sentence is "undefined", that is, in IE, the Array does not have a foreach method.
2. Make IE compatible with the Foreach method
Since the IE array does not have a foreach method, we will add this prototype method to it manually.
//Array.foreach implementation for IE support: //Https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEachDetailed introduction can refer toif(!Array.prototype.forEach) {Array.prototype.forEach=function (callback, thisarg) {varT, K; if( This==NULL) { Throw NewTypeError ("This is a null or not defined"); } varO = Object ( This); varLen = O.length >>>0;//Hack to convert O.length to a UInt32 if({}.tostring.call (callback)! ="[Object Function]") { Throw NewTypeError (callback +"is not a function"); } if(thisarg) {T=Thisarg; } k=0; while(K <Len) { varKvalue; if(kinchO) {Kvalue=O[k]; Callback.call (T, Kvalue, K, O); } k++; } }; }
JavaScript array loop traversal, array element plus fixed element foreach