Nodejs Array ForEach forEach()

Here you can find the source of forEach()

Method Source Code

/* eslint-disable no-extend-native */
Array.prototype.forEach = Array.prototype.forEach || _forEach
Array.prototype.every = Array.prototype.every || _every

Array.prototype.indexOf = Array.prototype.indexOf || function(member) {
  for(var idx = 0; idx < this.length; ++idx) {
    if(this[idx] === member) {
      return idx/*from ww w  .j  ava2s  . co m*/
    }
  }
  return -1
}

Array.prototype.remove = function(member, howMany) {
  var idx = this.indexOf(member)
  if(-1 !== idx) {
    this.splice(idx, howMany || 1)
  }
}

Related

  1. forEach
    ===
    
  2. forEach(a)
    "use strict"
    Array.prototype.forEach = function(a) {
      for (let i = 0; i < this.length; i++) a(this[i], i, this)
    
  3. 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);
    };
    
  4. forEach(callback)
    Array.prototype.forEach = function(callback){
        let arr = this;
        for (var i = 0; i < arr.length; i++) {
            callback(arr[i], i, arr);
    
  5. forEach(callback)
    Array.prototype.forEach = function(callback){
      var a = 0,
        len = this.length;
      while(a < len){
        callback(this[a], a++, this);
    };