forEach array iteration vs for array iteration

Edit on GitHub

Setup

Tests

  • forEach array iteration

    function() {
      var testArray = [1,2,3,4];
      testArray.forEach(function(node) {
        document.body.innerHTML += node;
      });
    }
  • for array iteration

    function() {
      var testArray = [1,2,3,4];
      for (var i = 0; i < testArray.length; i++) {
        document.body.innerHTML += testArray[i];
      }
    }