Concat ()
method is used to concatenate two or more strings.
The method does not alter the existing array, but only returns a copy of the concatenated array.
Arrayobject.concat (Arrayx,arrayx,......, Arrayx)
The concat () method converts all its arguments to a string, then connects sequentially to the end of the string stringobject and returns the concatenated string. Please note that the Stringobject itself has not been changed.
Tip: Note that using the "+" operator for string connection operations is usually easier.
Example 1
var str1= "Hello"
var str2= "world!"
document.write (Str1.concat (STR2))//Hello world!
document.write (STR1)//Hello
Example 2
var a = [1, ' ABC ', 3];
document.write (A.concat (4,5)); 1,abc,3,4,5
document.write (a)//1,abc,3
document.write (a[1])//ABC
Example 3
var arr = new Array (3)
Arr[0] = 1
ARR[1] = 2
ARR[2] = 3
var arr2 = new Array (3)
ARR2[0] = 4
ARR2[1] = 5
ARR2[2] = 6
var arr3 = new Array (3)
Arr3[0] = 7
ARR3[1] = ' abc '
ARR3[2] = 9
document.write (Arr.concat (ARR2))//1,2,3,7,8,9
document.write (Arr.concat (ARR2,ARR3))//1,2,3,4,5,6,7,abc,9
JavaScript's concat () method