Nodejs Object Value Iterate each(callback, context)

Here you can find the source of each(callback, context)

Method Source Code

// Iterates over every key-value pair of an object.
// Discards parents' (prototypal) properties.
Object.prototype.each = function (callback, context)
{
   var key, // www .j ava 2  s  .c om
      value;
   
   for (key in this)
   {
      if (this.hasOwnProperty( key ))
      {
         value = this[key];

         context ? callback.call(context, value, key) : callback(value, key);
      }
   }

   return null;
}

Related

  1. each(f)
    Object.prototype.each = function(f) {
      for(var key in this) {
        if(this.hasOwnProperty(key)) {
          f(key, this[key]);
    };
    
  2. each(iterator)
    Object.prototype.each = function(iterator) {
      var key;
      for(key in this) {
        iterator(this[key], 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);
    };