
How to Merge Arrays Together in Javascript
There are a number of ways to merge arrays together in JavaScript. You can either use Array.concat
:
// Using Array.concat
const array1 = ['📗', '📘'];
const array2 = ['📕', '📙'];
array1.concat(array2);
You can also merge more than two arrays into one using concat
in the following way:
// Using Array.concat
const first = ['1️⃣', '2️⃣'];
const second = ['3️⃣', '4️⃣'];
const third = ['5️⃣', '6️⃣'];
// This will result in ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣']
[].concat(first, second, third);
Keep in mind that both solution will return a new array instead of modifying the existing ones. Another way to combine arrays together, is by using destructuring:
// Using the destructuring assignment
const array1 = ['📗', '📘'];
const array2 = ['📕', '📙'];
[...array1, ...array2];
Again, this will create a new array instead of modifying the originals. You can also create a simple function to combine as many arrays as you would like:
function combine() {
const array = [];
[...arguments].forEach(arg => {
array.push(...arg);
});
return array;
}
combine([1]); // returns [1]
combine([1], [2]); // returns [1, 2]
combine([1], [2], [3]); // returns [1, 2, 3]
This works by making use of the arguments object, that is accessible inside functions.


Resources:

Tired of looking for tutorials?
You are not alone. Webtips has more than 400 tutorials which would take roughly 75 hours to read.
Check out our interactive course to master JavaScript in less time.
Learn More