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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *