Last active
April 10, 2024 03:58
-
-
Save 0xF5T9/1e5829dfd0ae1f0a1323eee24b5d613a to your computer and use it in GitHub Desktop.
Javascript Promise.all() example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.all([ | |
fetch('https://jsonplaceholder.typicode.com/posts').then((res) => res.json()), | |
fetch('https://jsonplaceholder.typicode.com/users').then((res) => res.json()), | |
fetch('https://jsonplaceholder.typicode.com/comments').then((res) => res.json()) | |
// Fetch more data if needed ... | |
]) | |
.then((data) => { | |
console.log('Do something with this data: ', data); | |
// Do something ... | |
}) | |
.catch((error) => { | |
console.log('Error messsage: ', error); | |
// Error handlings ... | |
}) | |
.finally(() => { | |
console.log('Do something on \'finally\''); | |
// Do something ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment