Skip to content

Instantly share code, notes, and snippets.

@0xF5T9
Last active April 10, 2024 03:58
Show Gist options
  • Save 0xF5T9/1e5829dfd0ae1f0a1323eee24b5d613a to your computer and use it in GitHub Desktop.
Save 0xF5T9/1e5829dfd0ae1f0a1323eee24b5d613a to your computer and use it in GitHub Desktop.
Javascript Promise.all() example
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