Skip to content

Instantly share code, notes, and snippets.

View vinodnimbalkar's full-sized avatar
🎯
Focusing

Vinod Nimbalkar vinodnimbalkar

🎯
Focusing
View GitHub Profile

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do: