Sometimes, we want to use Promise.all with Axios and JavaScript.
In this article, we’ll look at how to use Promise.all with Axios and JavaScript.
How to use Promise.all with Axios and JavaScript?
To use Promise.all with Axios and JavaScript, we call Promise.all
with an array of promises returned by Axios.
For instance, we write
const URL1 = "https://www.something.com";
const URL2 = "https://www.something1.com";
const URL3 = "https://www.something2.com";
const promise1 = axios.get(URL1);
const promise2 = axios.get(URL2);
const promise3 = axios.get(URL3);
const values = await Promise.all([promise1, promise2, promise3]);
to call Promise.all
with an array with promises returned by axios.get
.
Then we get the resolve value of each promise in the values
array in the order they’re listed in the array that we called Promise.all
with.
Conclusion
To use Promise.all with Axios and JavaScript, we call Promise.all
with an array of promises returned by Axios.