Answers for "how to make foreach loop async in node js"

2

async await forEach

// Array.prototype.forEach is not designed for asynchronous code.
// Instead use await Promise.all to process all in parallel if the order doesn't matter.
await Promise.all(array.map(async (element) => {
  await someFunction(element);
}))
Posted by: Guest on November-21-2021
1

async foreach

[1, 2, 3].forEach(async (num) => {  await waitFor(50);  console.log(num);});console.log('Done');
Posted by: Guest on September-15-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language