vineet sah vineet sah - 1 month ago 9
Node.js Question

How to use object in Asyn forEachSeries

I have an object and would like to fetch their key and value of each iterator.

For example:-

var async=require('async')
var a1={'1':'fadfa','2':2,'3':3};
async.forEachSeries(a1, function(n1, callback) {
console.log(n1); // here i need key and value in each iterator.
callback();
});

Answer

use this:

var async=require('async')
var a1={'1':'fadfa','2':2,'3':3};
async.forEachSeries(Object.keys(a1), function(n1, callback) {
    var key = n1;
    var value = a1[key];
    console.log(key + " " + value);
    callback();
});
Comments