Concat vs Spread vs Push

Edit on GitHub

Setup

const data = Array(1000).fill(null).map((x, i) => i);
const reduce = (func) => data.reduce((o, x) => func(o, x), []);

Tests

  • Concat

    reduce(
      (obj, x) => obj.concat(x)
    );
  • Spread

    reduce(
      (obj, x) => [ ...obj, x ]
    );
  • Push

    reduce(
      (obj, x) => {
        obj.push(x);
        return obj;
      }
    );