Categories
JavaScript Answers

How to use the async lib – async.foreach with object with Node.js?

Spread the love

To use the async lib – async.foreach with object with Node.js, we call forEach with a callback for each item.

For instance, we write

async.forEach(
  Object.keys(dataObj),
  (item, callback) => {
    console.log(item);
    callback();
  },
  (err) => {
    console.log("iterating done");
  }
);

to call forEach with a callback with the callback parameter that we call in the callback.

The callback in the 2nd argument is called when the async process is done.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.