TLDR: Use for...of
instead of forEach
in asynchronous code.
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: