Answers for "foreach with await javascript"

3

ts await foreach loop

async function printFiles () {
  const files = await getFilePaths();

  await Promise.all(files.map(async (file) => {
    const contents = await fs.readFile(file, 'utf8')
    console.log(contents)
  }));
}
Posted by: Guest on July-24-2020
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
0

use await in for each

files.forEach(async (file) => {
    const contents = await fs.readFile(file, 'utf8')
})
Posted by: Guest on March-04-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language