for vs Array#forEach vs Array#map

Edit on GitHub

for vs forEach vs map

Setup

var arr = Array.from({ length: 100 });

Tests

  • for

    for (let i = 0; i < arr.length; i++) {
      arr[i] = arr[i] * 2;
    }
  • Array#forEach

    arr.forEach((val) => {
      val = val * 2;
    });
  • Array#map

    arr = arr.map(val => val * 2);