return array after foreach async code example

Example 1: foreach async typescript

for (const file of files) {
    const contents = await fs.readFile(file, 'utf8');
    console.log(contents);
  }

Example 2: 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)
  }));
}

Example 3: foreach await js

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

  for (const file of files) {
    const contents = await fs.readFile(file, 'utf8');
    console.log(contents);
  }
}