Iterates over an object - Node.js Object

Node.js examples for Object:Object Operation

Description

Iterates over an object

Demo Code

//iterates over an object. the callback receives the key, value and the obejct.
// > Object.iterate( {a : 4, b : 5}, console.log.bind(console) )
// a 4 { a: 4, b: 5 }
// b 5 { a: 4, b: 5 }
Object.iterate = function ( obj, cb, thisArg ) {
  Object.keys( obj ).forEach(function (key) {
    cb.call( thisArg, key, obj[key], obj );
  });//from ww  w. ja  v a  2 s .c o  m
};

Related Tutorials