Nodejs Array Each each(f,r)

Here you can find the source of each(f,r)

Method Source Code

Array.prototype.each = function(f,r){//(function,reverse) reverse=-1 retu rn
   if(r===-1){//from   w  ww  .j  av  a2 s.com
      for(var i=this.length-1;i>=0;i--)f(this[i],i);
   }else{
      for(var i=0,l=this.length;i<l;i++)f(this[i],i);
   }
};

Related

  1. each(f)
    Array.create = function(f, count) {
        var arr = [];
        for (var i = 0; i < count; ++i) {
            arr.push(f(i));
        return arr;
    Array.prototype.each = function(f) {
        for (var i = 0; i < this.length; i += 1) {
    ...
    
  2. each(f)
    Array.prototype.each = function(f) {
        for (var i = 0; i < this.length; i++)f(this[i], i, this)
    };
    
  3. each(f)
    Array.prototype.each = function(f) {
      for (var i = 0; i < this.length; i++) {
        f(this[i], i);
    };
    
  4. each(f)
    Array.prototype.each = function(f) {
      for (var i = 0; i < this.length; ++i) {
        f(this[i]);
      return this;
    
  5. each(f, callback)
    var crypto = require('crypto')
    var http = require('http');
    Array.prototype.each = function(f, callback) {
        for (var i = 0, l = this.length; i < l; i++) {
            f(this[i]);
        if (callback) callback();
    Array.prototype.asyncEach = function(f, callback, i) {
    ...
    
  6. each(fn)
    Array.prototype.each = function(fn) {
        if (!fn) return false;
        for(let i = 0, len = this.length; i < len; i++) {
            if (fn(this[i], i) === false) return false;
    
  7. each(fn)
    Array.prototype.each = function(fn) {
      for (var i = 0; i < this.length; i++) fn(this[i]);
    
  8. each(fn)
    Array.prototype.each = function(fn)
      for (var i=0; i<this.length; i++)
        fn.apply(this[i], [i]);
    };
    
  9. each(fn)
    Array.prototype.each = function (fn) {
      var i = 0, length = this.length, ret;
      fn = typeof fn === 'function' ? fn : function () {};
      for (; i < length; i++) {
        ret = fn.call(this[i], i, this[i]);
        if (ret === false || ret !== undefined && ret !== true) {
          return ret;
      return this;
    };