Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
JavaScript promises provide an easier, more efficient way to fire off and keep track of multiple async operations at the same time with Promise.all. In this video, you'll learn how to manage multiple fetch requests with promise.all.
Resources
Below is another way you might compose promises with fetch()
and Promise.all
. View the full example in this Workspace snapshot.
// store urls to fetch in an array
const urls = [
'https://dog.ceo/api/breeds/list',
'https://dog.ceo/api/breeds/image/random'
];
// use map() to perform a fetch and handle the response for each url
Promise.all(urls.map(url =>
fetch(url)
.then(checkStatus)
.then(parseJSON)
.catch(logError)
))
.then(data => {
// do something with the data
})
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Gavin Eyquem
Front End Web Development Techdegree Student 22,114 Points1 Answer
-
Homero Mendoza
12,782 Points1 Answer
-
Kendall McCall
8,177 Points2 Answers
-
Caroline Louw
12,155 Points1 Answer
-
Farid Lavizadeh
12,006 Points3 Answers
-
Jiten Mehta
Front End Web Development Techdegree Graduate 21,209 Points3 Answers
-
Rushabha Jain
Full Stack JavaScript Techdegree Student 11,141 Points1 Answer
-
Jake Morris
Full Stack JavaScript Techdegree Graduate 17,735 Points2 Answers
-
Nguyen Pham
Full Stack JavaScript Techdegree Graduate 17,299 Points0 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up