Nodejs Array ForEach forEach(fn)

Here you can find the source of forEach(fn)

Method Source Code

Array.prototype.forEach=function(fn){
    var arr=this;
    var length=this.length;
    for(var i=0;i<length;i++){
        fn(arr[i],i,arr);/*from   w  ww.  j  a va 2 s  . co m*/
    }
}

Related

  1. 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);
    };
    ...
    
  2. forEach(cb)
    Array.prototype.forEach = function(cb){
      for(var k in this) cb(this[k]);
    };
    
  3. forEach(cb)
    Array.prototype.forEach = function(cb) {
        for (var i = 0; i < this.length; i++) {
            cb(this[i]);
    };
    
  4. forEach(cb)
    'use strict';
    Array.prototype.forEach = function(cb) {
      for(let i = 0 ; i < this.length ; i++) {
        cb(this[i]);
    };
    
  5. forEach(fn)
    Array.prototype.forEach  = function(fn) {
      for (var i = 0; i < this.length; i++) fn(this[i]);
    
  6. forEach(fn)
    Array.prototype.forEach = function(fn)
        for (var i=0;i<this.length;i++)
            fn(this[i]);
    
  7. forEach(fn, context)
    Array.prototype.forEach = function(fn, context) {
      if (typeof fn != "function") {
        throw new TypeError(fn + " is not a function");
      if (typeof context === 'undefined') {
        context = this;
      for (var i = 0, l = this.length; i < l; ++i) {
        fn.call(context, this[i], i, this);
    ...
    
  8. forEach(fun /*, thisp */)
    Array.prototype.forEach = Array.prototype.forEach || function(fun ) {
      "use strict";
      if (this === void 0 || this === null) throw new TypeError();
      var t = Object(this);
      var len = t.length >>> 0;
      if (typeof fun !== "function") throw new TypeError();
      var thisp = arguments[1];
      for (var i = 0; i < len; i++) {
        if (i in t) fun.call(thisp, t[i], i, t);
    ...
    
  9. forEach(fun /*, thisp*/)
    Array.prototype.forEach = function(fun )
        var len = this.length;
        if (typeof fun != "function")
          throw new TypeError();
        var thisp = arguments[1];
        for (var i = 0; i < len; i++)
          if (i in this)
    ...