ForEach is added to the ECMA-262 standard in version 5, which does not support forEach () for IE 8 or earlier versions (). this article explains how to solve the problem that IE8 does not support forEach (). For more information about coders, see.
forEachIs added to the ECMA-262 standard in version 5; so it may not exist in other implementations of the standard, you can call
forEachInsert the following code and use it if it is not supported locally.
forEach(). The algorithm is specified in ECMA-262 5th. Algorithm hypothesis
ObjectAnd
TypeErrorHas their initial values.
callback.callEquivalent
Function.prototype.call().
if ( !Array.prototype.forEach ) { Array.prototype.forEach = function forEach( callback, thisArg ) { var T, k; if ( this == null ) { throw new TypeError( "this is null or not defined" ); } var O = Object(this); var len = O.length >>> 0; if ( typeof callback !== "function" ) { throw new TypeError( callback + " is not a function" ); } if ( arguments.length > 1 ) { T = thisArg; } k = 0; while( k < len ) { var kValue; if ( k in O ) { kValue = O[ k ]; callback.call( T, kValue, k, O ); } k++; } };}