Array#forEach vs for

Edit on GitHub

Setup

let count = 1000 * 1000
const a = [];
const b = [];


do {
  a.push({
    title: 'item ' + count
  });
} while(--count);

Tests

  • Array#forEach

    a.forEach(x => {
      b.push(x);
    });
  • for

    for (let i = 0; i < a.length; i++) {
      b.push(a[i]);
    });