Visual Explanation: JavaScript Array.concat()

Max N
2 min readDec 5, 2019

Today we are going to learn about another JavaScript method under the Array class called .concat().

What this method does is it merges two or more arrays. This method outputs the new merged array without altering the original arrays. Let’s show an example.

We have two arrays:

let arr1 = [4,2,1];
let arr2 = [1,2,1];

Then, we use Array.concat to merge the two arrays:

arr1.concat(arr2);

The output will be one large array concatenating arr2 to arr1:

[4,2,1,1,2,1] // expected output

Since we concatenated arr2 to arr1, the values in the arr2 array will come after the values in the arr1 array. If we wanted to flip the order, we will use the method to concatenate arr1 to arr2:

--

--

Max N

A writer that writes about JavaScript and Python to beginners. If you find my articles helpful, feel free to follow.