Nodejs Array ForEach forEach(callback, context)

Here you can find the source of forEach(callback, context)

Method Source Code

Array.prototype.forEach = function (callback, context) {
    for (var index in this) {
        var item = this[index];
        if (!callback(index, item, context)) {
            break;/*from   w ww  . j a v  a  2  s  . c  om*/
        }
    }
};

Related

  1. forEach(action, index)
    Array.prototype.forEach = Array.prototype.forEach || function(action, index) {
        for (var i=0,l=this.length; i<l; i++) {
            action(this[i], index);
    };
    
  2. forEach(callback)
    Array.prototype.forEach = function(callback){
        let arr = this;
        for (var i = 0; i < arr.length; i++) {
            callback(arr[i], i, arr);
    
  3. forEach(callback)
    Array.prototype.forEach = function(callback){
      var a = 0,
        len = this.length;
      while(a < len){
        callback(this[a], a++, this);
    };
    
  4. forEach(callback)
    Array.prototype.forEach = Array.prototype.forEach || function (callback) {
        var self = this;
        for (var i = 0; i < self.length; i++) {
            var item = self[i];
            callback(item, i, self);
    
  5. forEach(callback, context)
    Array.prototype.forEach = Array.prototype.forEach || function (callback, context) {
      context = context || window;
      var l = this.length;
      for (var i = 0; i < l; i++)
        callback.call(context, this[i], i, this);
    };
    
  6. forEach(callback, thisArg)
    Array.prototype.forEach = function (callback, thisArg) {
      if (typeof callback !== 'function') {
        throw new TypeError(callback + ' is not a function.');
      var len = this.length;  
      for (var i = 0; i < len; i++) {
        callback.call(thisArg, this[i], i, this);
    };
    ...
    
  7. forEach(cb)
    Array.prototype.forEach = function(cb){
      for(var k in this) cb(this[k]);
    };
    
  8. forEach(cb)
    Array.prototype.forEach = function(cb) {
        for (var i = 0; i < this.length; i++) {
            cb(this[i]);
    };
    
  9. forEach(cb)
    'use strict';
    Array.prototype.forEach = function(cb) {
      for(let i = 0 ; i < this.length ; i++) {
        cb(this[i]);
    };