Nodejs Array Each each(fn, last)

Here you can find the source of each(fn, last)

Method Source Code

Array.prototype.each = function(fn, last) {
    if (typeof fn != "function") return false;
    //from   ww  w  .j  a v a  2s.co  m
    for (var index = 0; index < this.length; index++) {
            fn(this[index], index);
    }

    if (last) last();
};

Related

  1. each(fn)
    Array.prototype.each = function(fn) {
      for (var i = 0; i < this.length; i++) fn(this[i]);
    
  2. each(fn)
    Array.prototype.each = function(fn)
      for (var i=0; i<this.length; i++)
        fn.apply(this[i], [i]);
    };
    
  3. 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;
    };
    
  4. each(fn)
    Array.prototype.each = function(fn){
        fn = fn || Function.K;
         var a = [];
         var args = Array.prototype.slice.call(arguments, 1);
         for(var i = 0; i < this.length; i++){
             var res = fn.apply(this,[this[i],i].concat(args));
             if(res != null) a.push(res);
         return a;
    ...
    
  5. each(fn)
    Array.prototype.each = function(fn) {
      for(var i = 0; i < this.length; i++) {
        fn(i, this[i]);
      };
    };
    
  6. each(fnCallback)
    Array.prototype.each = function(fnCallback) {
        var value = null;
        for (var elementIndex in this) {
            if (this.hasOwnProperty(elementIndex)) {
                value = fnCallback.apply(this[elementIndex], [elementIndex, value]);
        return (value) ? value : this;
    };
    ...
    
  7. each(fun)
    Array.prototype.each = function(fun) {
        for (var i = 0; i < this.length; i++) {
            fun(this[i]);
    };
    
  8. each(fun)
    function emptyFn() {}
    function random(n) {
        return +n ? Math.floor(Math.random() * (n+1)) : Math.random();
    Array.prototype.each = Object.prototype.each = Function.prototype.each = function(fun) {
        for (var key in this) {
            if (this.hasOwnProperty && this.hasOwnProperty(key)) {
                if (fun.call(this, this[key], key, this) === false) {
                    return;
    ...
    
  9. each(func)
    Array.prototype.each = function (func) {
        return _.each(this, func);
    };