DEV Community

Discussion on: How To For Loop Through Anything in JS

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

jsperf.com/loop-vs-map-vs-foreach/22

So, map and classical for loop. But it is usually more semantically to use forEach rather than map, albeit slow.

for loop isn't so bad, but it depends on the use case.

Collapse
 
leob profile image
leob

Why is it more semantical to write "arr.forEach(...)" instead of "for (... of arr)" ? Seems merely a matter of syntax and taste to me ...

Thread Thread
 
jacobmparis profile image
Jacob Paris

I would absolutely consider this to be a matter of taste

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt

I meant arr.forEach() vs arr.map().

for of and for in are another species, and is whether you want it to be functional or procedural. Neither is better than the others.