How do I await a list of Promises in JavaScript/TypeScript? How do I await a list of Promises in JavaScript/TypeScript? typescript typescript

How do I await a list of Promises in JavaScript/TypeScript?


This is correct:

const bar = await Promise.all(promiseArray);

await Promise.all([...]) takes an array of Promises and returns an array of results.

bar will be an array: ['hello', ..., 'hello']

You can also deconstruct the resulting array:

const [bar1, ..., bar10] = await Promise.all(promiseArray);console.log(bar1); // helloconsole.log(bar7); // hello