Nodejs Array Each each()

Here you can find the source of each()

Method Source Code

// Array.each - Array.forEach alias.
Array.prototype.each = Array.prototype.forEach;

// Object.eachKey - Iterates over key/value pairs.
Object.prototype.eachKey = function (cb) {
  var k = Object.keys(this);
  for (var i = 0; i < k.length; i++)
    cb(k[i], this[k[i]]);//from ww w .  j  a  va  2s . c o m
};

// times - Runs cb() n times.
var times = function (n, cb) {
  for (var i = 0; i < n; i++) cb(n);
};

// Array.range - for a 2-item array, creates an array of numbers in that range.
Array.prototype.range = function () {
  var ar = [];
  for (var i = this[0]; i <= this[1]; i++)
    ar.push(i);
  return ar;
};

Related

  1. each( func )
    Array.prototype.each = function( func ) {
      for( var i=0; i<this.length; i++ ) {
        func( this[i], i );
      return this;
    };
    
  2. each()
    Array.prototype.each = function () {
      this.forEach.apply( this, arguments );
      return this;
    };
    
  3. each(action)
    Array.prototype.each = function(action) {
      var args = getArgs(1,arguments);
      var arr = this;
       for (var i = 0, l = arr.length; i < l; ++i) {
            action.apply(this,[arr[i],i].concat(args));
    };
    
  4. each(action)
    Array.prototype.each = function(action){
        for(var i = 0; i< this.length; i++){
            action(this[i], i);
    };
    
  5. each(action)
    Array.prototype.each = function(action) {
        for (var i = 0, l = this.length; i < l; ++i) {
            action(this[i], i);
    };