Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is the most efficient way to concatenate N arrays?

What is the most efficient way to concatenate N arrays of objects in JavaScript?

The arrays are mutable, and the result can be stored in one of the input arrays.
by

1 Answer

vishaljlf39
For people using ES2015 (ES6)
You can now use the Spread Syntax to concatenate arrays:
const arr1 = [0, 1, 2],
arr2 = [3, 4, 5];

const result1 = [...arr1, ...arr2]; // -> [0, 1, 2, 3, 4, 5]

// or...

const result2 = [...arr2, ...arr1]; // -> [3, 4, 5, 0, 1, 2]

Login / Signup to Answer the Question.