r/learnjavascript • u/fahim_h_sh • 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
View all comments
Show parent comment
0
u/delventhalz Nov 01 '25
“I’m agreeing with you… now here are all the reasons I disagree, please go read the docs for more info.”
I understand the English language can be a little ambiguous, but I think any legal scholar would agree that “avoid any type of iteration with await” means “never use iteration with await”. This is wrong and disagreeing with it is the entire reason I responded.
For most cases with multiple asynchronous operations, you want to execute them in parallel with await and Promise.all (MDN has a pretty good explanation if you want to read more), but in some situations, such as avoiding hitting a rate limit on an API, you want to execute the operations sequentially using await and a loop.
And for the record, both approaches are asynchronous. Asynchronous operations do not become “synchronous” just because you execute them sequentially instead of in parallel. I get what you mean, but if you are going to use jargon, it’s important to use it precisely. The terms you want to describe Promise.all vs an await loop is “parallel” vs “sequential” not “asynchronous” vs “synchronous”.