DEV Community

[Comment from a deleted post]
Collapse
 
brieucp profile image
brieucp • Edited

Looking at perf, the basic for loop is superior to any of the other. jsperf.com/for-vs-foreach/75.

And Array.prototype.map merits to be considered as an alternative to foreach jsperf.com/loop-vs-map-vs-foreach.

Collapse
 
thecodingalpaca profile image
Carlos Trapet

In some situations we have to consider code readability over to-the-nanosecond performance.
But yeah, it is well known that the classic for-loop outperforms any other loop by a very large margin.

Collapse
 
brieucp profile image
brieucp

Following @si response. Please note that it is (not probably, with absolute certainty) a bad practice to use map instead of forEach. But the fact is that map can run twice as fast as forEach, which is boringly slow.