mksoft : |
אתה יכול לבנות לולאה על המערך, באותו עמוד שקישרתי לעיל, ראה גם sequences:
https://github.com/kriskowal/q#sequences |
קוד: |
// define an array of urls const urls = [...]; function downloadAllInOrder() { for (let url of urls) { const res = await fetch(url); const body = await res.text(); console.log(body); } } |
קוד: |
// define an array of urls const urls = [...]; function downloadAllInOrder() { const responses = await Promise.all(urls.map(fetch)); const bodies = await Promise.all(responses.map(r => r.text())); // now bodies is an array of all the responses console.log(bodies[2]); } |