var arr1 = [1, 2, 3]; var arr2 = ['a', 'b', 'c']; var mergeArr = arr1.concat(arr2) console.log(mergeArr); // [1, 2, 3, "a", "b", "c"];
The output of the above code is given below:
[1, 2, 3, "a", "b", "c"]
We can see that, our output contains all the elements of the two arrays that we have taken. The array is now the combination of those arrays.
Well, in our example we have just taken two arrays. But with the contact() method, you can combine more than two arrays.
Here we have taken two arrays into a variable and pass it to the contact() method. We store the final joined array in another variable.
array1.concat(array2, array3, array4, ..., arrayN)
I hope you learn something from this post.