While higher-order array methods like .map(), .filter(), and .reduce() are idiomatic and readable, they are not always the most performant choice for hot paths or large datasets.
1. The Cost of Chaining
Every time you chain an array method, JavaScript typically allocates a new intermediate array. For example, arr.filter(...).map(...) iterates twice and creates two new arrays. On massive datasets, this causes memory spikes and Garbage Collection pressure.
2. Unified Loops
A single for...of loop can perform filtering, mapping, and reduction in one pass without allocating intermediate structures.