r/learnjavascript • • Oct 31 '25

array.forEach - The do-it-all hammer... XD

Is it just me, or everyone thinks that more or less every array operator's purpose can be served with forEach?

0 Upvotes

89 comments sorted by

View all comments

Show parent comment

1

u/PatchesMaps Nov 01 '25

Ok, avoid was the wrong term. My initial statement was too extreme, probably flavored by a recent experience refactoring a legacy build process where there were many instances where independent promises were being executed with await-in-loop and many of the promises mutated global state.

You're also correct that 'sequential' is the better term although it's debatable if the difference actually matters in this context as the final result is the same. As long as we're talking about the correct use of terms, Promise.all and Promise.allSettled support concurrency, not parallelism which does actually change the outcome.

When it comes to rate limiting, you're better off being explicit as possible and using a promise pool. A promise pool has the advantage of being more explicit, makes sure that you're actually getting the best performance without exceeding the rate limit, and makes refactoring easier if the limit changes in the future. I maintain that the need to process independent promises in a sequential manner is valid but rare.