title: Why Array.forEach is slower than for() loop in Javascript?
body: <p>can anyone tell me whats the reason that array.forEach is slower than for loop in javascript. Is there any particular reason.</p>
  
  <p>Here's the code that I was trying to find the performance.</p>
  
  <pre><code>// Populate the base array
      var arr = [];
      for (var i = 0; i &lt; 1000; i++) {
        arr[i] = i;
      }
  
      function someFn(i) {
        return i * 3 * 8;
      }
  </code></pre>
  
  <p>Using Array.forEach :</p>
  
  <pre><code>arr.forEach(function (item){
    someFn(item);
  })
  </code></pre>
  
  <p>Using for loop : </p>
  
  <pre><code>for (var i = 0, len = arr.length; i &lt; len; i++) {
    someFn(arr[i]);
  }
  </code></pre>
  
  <p>I tested it on test runner . Here are the results:
  <a href="https://i.stack.imgur.com/4seSe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4seSe.png" alt="enter image description here"></a></p>
  
  <p>As you can see Array.ForEach is 96% slower than for loop.
  Thanks in advance. </p>