Example 1 — Awaiting promises in an array
Arrays are sync iterables; map to promises separately.
JavaScript
const ps = [Promise.resolve(1), Promise.resolve(2)];
(async () => {
for (const p of ps) console.log(await p);
})();How It Works
- for...of over promises.
- await each promise inside.
