Nodejs Array Each each(func)

Here you can find the source of each(func)

Method Source Code

// Ruby = [4, 5, 6].each { |element| puts "#{element}" }
// JS = [4, 5, 6].each(function(index) { alert(index + ": " + this); })
Array.prototype.each = function(func) {
  function each(array, func) {
  for (var i=0; i<array.length; ++i) {
    func.call(array[i], i);/*w  w w  . j a va 2  s  . c o m*/
  }
}
 each(this, func); 

};

Related

  1. each(fn, last)
    Array.prototype.each = function(fn, last) {
        if (typeof fn != "function") return false;
        for (var index = 0; index < this.length; index++) {
                fn(this[index], index);
        if (last) last();
    };
    
  2. 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;
    };
    ...
    
  3. each(fun)
    Array.prototype.each = function(fun) {
        for (var i = 0; i < this.length; i++) {
            fun(this[i]);
    };
    
  4. 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;
    ...
    
  5. each(func)
    Array.prototype.each = function (func) {
        return _.each(this, func);
    };
    
  6. each(func)
    Array.prototype.each = function (func) {
      var arr = this;
      for (var i = 0; i < arr.length; i++) {
        func(arr[i]);
    
  7. each(func)
    Array.prototype.each = function(func) {
      for(var i = 0; i < this.length; i++)
        func(this[i]);
    
  8. each(func, scope)
    Array.prototype.each = function(func, scope) {
        for (var index = 0; index < this.length; index++) {
            func.call(scope || this, this[index]);
    };
    
  9. each(handler, context)
    Array.prototype.each = function (handler, context) {
        var size = this.length
        if (typeof context == "undefined") context = this
        for (var i = 0; i < size; i++) {
            if (handler.call(context, this[i], i) == false) break