I’m sure you must have had a scenario where you had to join or merge two different Arrays. Well, let me tell you that its an easy task. JavaScript has a native method Array.concat() which does it. Let’s take a look at the syntax.

Array.concat(array1,array2,…arrayn);
Please note that the Array here is not the Array object but an Array variable previously declared.

The Array.concat() method accepts two or more array to be concatenated or merged and returns the merged array. Let’s take a look at an example:

If you notice we concatenated the 1st array variable (arr1) with the other ones. Yes, that’s how the method works. You need to use the .concat() method on one of the existing Arrays to merge it with other arrays.  The original arrays would not get altered. Instead a new array is created and assigned to the variable you declared.

Hope you found the article to be useful. Do let us know your comments. Also do share it with your friends if you found this article to be useful.