I have been looking at Promise.all
for fetching multiple urls. I know that we can use Promise.all
and pass an array there, and then fetch the content.
Let's say I have two URLs in an array but one of them is not working. How can I still use Promise.all
? What is the other method fetching both? I would fetch both but if one of them is not working don't fetch the one that is not working.
const urls = [ instagramURL, facebookURL];
const thepromises = urls.map((url) => fetch(url)
.then((resp) => resp.json()));
Promise.all(thepromises).then((post) => {
console.log(post);
});