Hello readers, This is a quiz question I was doing for practice and I wanted to know what should be the best answer to this from the choices given.
The question below:-
you are tasked with fetching the HTTP status codes for a list of URL’s using fetch()(https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using-Fetch).
Fill in the missing JS:
async function fetchStatusCodes(urls) {
//?? fill the blank
return httpResponses.map((response) => response.status );
}
(async ()=>{
const statusCodes= await fetchStatusCodes([
"https://example.com"
"https://example.com/bar"
"https://example.com/baz"
]);
//statusCodes==[200,404,404]
})()
Select the best options
const httpResponses = await urls.map(async (url) => fetch(url));
const httpResponses = urls.map((url) => await fetch(url));
const httpResponses = Promise.all(urls, async (url) => fetch(url))
const httpResponses = await Promise.all(urls.map(async (url) => fetch(url)))
Thanks for reading, don’t mind any typos