Array.prototype.concat vs spread operator

Edit on GitHub

fa

Setup

const LIMIT = 1000;
const a = [];
const b = [];

for (let i = 0; i < LIMIT; i++) {
  const aa = [];
  const bb = [];
  for (let j = 0; j <= i; j++) {
    aa.push(j);
    bb.push(j);
  }
  a.push(aa);
  b.push(bb);
}

Tests

  • Array.prototype.concat

    const c = [];
    for (let i = 0; i < LIMIT;  i++) {
      c.push(a.concat(b));
    }
  • spread operator

    const c = [];
    for (let i = 0; i < LIMIT;  i++) {
      c.push([...a, ...b]);
    }