2016-10-07 31 views
0

我有一個對象,並希望獲取它們的每個迭代器的鍵和值。如何在Asyn中使用對象forEachSeries

例如: -

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(); 
}); 

回答

1

使用本:

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(); 
});