For loop vs Reverse for loop vs Array.forEach

Edit on GitHub

Test speed of array iteration

Setup

Tests

  • For loop

    for (let i = 0; testArray.length; i++) {
      const element = testArray[i];
      window.console.log('for loop', element);
    }
  • Reverse for loop

    for (let i = testArray.length - 1; i >= 0; i--) {
      const element = testArray[i];
      window.console.log('reverse for loop', element);
    }
  • Array.forEach

    testArray.forEach(element => { window.console.log('Array.forEach', element); };