Fetch API & Handling JSON Responses
What is the key difference between these two approaches?
const urls = ['api/1', 'api/2', 'api/3'];
async function fetchSequential(urls) {
const results = [];
for (const url of urls) {
const response = await fetch(url);
results.push(await response.json());
}
return results;
}
async function fetchConcurrent(urls) {
const responses = await Promise.all(urls.map(url => fetch(url)));
return Promise.all(responses.map(r => r.json()));
}