Node.js - Using the async lib - async.foreach with object

前端 未结 2 1759
说谎
说谎 2020-11-30 23:31

I am using the node async lib - https://github.com/caolan/async#forEach and would like to iterate through an object and print out its index key. Once complete I wou

2条回答
  •  孤街浪徒
    2020-12-01 00:13

    The final function does not get called because async.forEach requires that you call the callback function for every element.

    Use something like this:

    async.forEach(Object.keys(dataObj), function (item, callback){ 
        console.log(item); // print the key
    
        // tell async that that particular element of the iterator is done
        callback(); 
    
    }, function(err) {
        console.log('iterating done');
    });  
    

提交回复
热议问题