JavaScript Performance: for vs. foreach

I ran across a test of a for loop vs foreach and I was surprised at the difference when running the test in Chrome 38:


The for loop consistently came out over 40 times faster than the foreach.


  1. I believe JavaScript compiler eliminates the for loop at all in this case. I modified the test for more realistic results:

  2. Since jsPerf is down, what was the result?

  3. That is what the screenshot was for 🙂

  4. I believe he’s talking about ivan’s test though.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2019 Joseph Scott

Theme by Anders NorénUp ↑