geraintwhite / async-tools

Useful async functions
https://github.com/grit96/async-tools
MIT License
1 stars 1 forks source link

Handle objects in forEach{,Sync} #5

Closed geraintwhite closed 8 years ago

geraintwhite commented 8 years ago
async.forEach({1: 'hello', 2: 'world'},
  function(key, value, done) {
    console.log(key, value);
    done();
  },
  function fin(err) {
    if (err) { console.log(err); }
  });
geraintwhite commented 8 years ago

This may be useful but the same can be achieved with:

var obj = {1: 'hello', 2: 'world'};
async.forEach(Object.keys(obj),
  function(key, done) {
    console.log(key, obj[key]);
    done();
  },
  function fin(err) {
    if (err) { console.log(err); }
  });