DEV Community

Discussion on: Which Array Function When?

Collapse
 
jservoire profile image
Johann-S

Do you know if forEach is better in term of perf than for ?

Nice post !

Collapse
 
andrew565 profile image
Andrew Steele

According to this for is pretty much always faster than forEach, so if performance is more important than concise code (and it usually should be) a for loop is likely a better choice.

Collapse
 
darrenkopp profile image
Darren Kopp

Correct, as the forEach call will incur a penalty invoking the lambda expression. forEach could have equivalent performance if the JIT inlines the lamba method body, but it's safe to say always expect forEach to be a bit slower.