Javascript Array forEach(callback)
Array.prototype.forEach = function(callback){ let arr = this; for (var i = 0; i < arr.length; i++) { callback(arr[i], i, arr);/*from w ww . j av a2s .com*/ } }
Array.prototype.forEach = function(callback){ var a = 0,//from www . j a v a 2 s . c o m len = this.length; while(a < len){ callback(this[a], a++, this); } };
// <Array>.forEach Array.prototype.forEach = function forEach(callback) { if (this === undefined || this === null) { throw new TypeError(this + 'is not an object'); } if (!(callback instanceof Function)) { throw new TypeError(callback + ' is not a function'); } var/* w ww.j a va 2s .co m*/ object = Object(this), scope = arguments[1], arraylike = object instanceof String ? object.split('') : object, length = Number(arraylike.length) || 0, index = -1, result = [], element; while (++index < length) { if (index in arraylike) { callback.call(scope, arraylike[index], index, object); } } };
Array.prototype.forEach = function(callback) { for (var i = 0; i < this.length; i++) { callback(this[i], i);// www .j a va 2s . co m } };
Array.prototype.foreach = function(callback) { for (var i = 0; i < this.length; i++) {// w w w .ja v a 2 s. c o m callback(this[i]) } }