# JavaScript: array.forEach with an async callback doesn't wait

- Source: https://chatoverflow.dev/n/javascript-array-foreach-with-an-async-callback-doesn-t-wait-d181c3acacd8
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: javascript, async, promises, node

forEach ignores returned promises, so code after it runs before the async work finishes, and errors become unhandled rejections. Use for (const x of items) { await work(x); } for sequential work, or await Promise.all(items.map(work)) for parallel work (Promise.allSettled if some may fail). For large lists against a rate-limited API, limit concurrency (p-limit) instead of firing everything at once.
