Concatenating Arrays is another useful array method that can be used for many different purposes. The syntax of the method looks like this:
concat() methods inserts the element of
arr2 (the array inside the brackets) to the end of
arr 1 (the first array). This method returns a new array as a result of adding the two arrays. The two arrays used in the concatenation remain unchanged after the method is called.
As shown above, the arrays
arr 1 and
arr 2 are concatenated to produce
arr 3. The resulting array
arr 3 has both the elements of the first array as well as the second array. This method will prove to be useful when you want to split a big array into different smaller arrays for specific calculations before making them a big array again. The
arrayname.concat() method is similar to the
concat() method used when adding two strings together.