Categories
TypeScript Answers

How to await a list of promises in JavaScript or TypeScript?

Spread the love

Sometimes, we want to await a list of promises in JavaScript or TypeScript.

In this article, we’ll look at how to await a list of promises in JavaScript or TypeScript.

How to await a list of promises in JavaScript or TypeScript?

To await a list of promises in JavaScript or TypeScript, we call Promise.all with an array of promises.

For instance, we write

const bar = await Promise.all(promiseArray);

in an async function to call Promise.all with a promiseArray which is an array of promises.

Then we use await to return an array of the resolve value of all the promises and assign it to bar.

Conclusion

To await a list of promises in JavaScript or TypeScript, we call Promise.all with an array of promises.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.