Nodejs Object Value Iterate each(iterator)

Here you can find the source of each(iterator)

Method Source Code

// Each (object)/*  w ww .  j a va  2s . c o m*/
// -------------
// Iterates over each key/pair and
// passes the value and key at each stage.
Object.prototype.each = function(iterator) {
  var key;
  for(key in this) {
    iterator(this[key], key);
  }
}

Related

  1. each(callback, context)
    Object.prototype.each = function (callback, context)
      var key, 
        value;
      for (key in this)
        if (this.hasOwnProperty( key ))
          value = this[key];
    ...
    
  2. each(f)
    Object.prototype.each = function(f) {
      for(var key in this) {
        if(this.hasOwnProperty(key)) {
          f(key, this[key]);
    };
    
  3. each(object, callback, scope)
    Object.each = function(object, callback, scope) {
      for (var key in object) {
        callback.call(scope, key, object[key]);
    };
    
  4. forEach(callback, context)
    Object.prototype.forEach = function(callback, context) {
      var ctx = context || null;
        Object.keys(this).forEach(function (key) {
            callback.apply(ctx, [this[key], key]);
        }, this);
    };
    
  5. forEach(obj, callback)
    "use strict";
    Object.forEach = function(obj, callback) {
        return Object.keys(obj).forEach(key => callback(obj[key], key));
    
  6. loopItems(action, defaultResult)
    Object.prototype.loopItems = function(action, defaultResult) {
        var key, result;
        for (key in this) {
            if (this.hasOwnProperty(key)) {
          result = action(key, this[key]);
          if (result !== undefined) {
        return result;
        return defaultResult;
    };