Returns a new array, which is a combination of two or more arrays.
array1.concat([item1[, item2[, . . . [, itemN]]]])
Parameters
Array1
Required option. The array object to which all other arrays are to be connected.
Item1,.. ., itemn
Options available. Other items to connect to the end of array1 .
Description
The concat method returns an Array object that contains a connection to the array1 and any other items provided.
Items to add (item1 ... itemn) are added to the array in Left-to-right order. If an item is an array, add its contents to the end of the array1 . If the item is not an array, it is added to the end of the array as a single array element.
The following is a copy of an element from the source array to the result array:
- For object parameters copied from the array being connected to the new array, the same object is still pointed to after replication. Whatever changes in the new array and source array will cause another change.
- For a numeric or string connection to a new array, only its value is copied. A change in the value of an array does not affect the value in the other array.
Example
The following example illustrates the use of the concat method when using an array:
function ConcatArrayDemo(){
var a, b, c, d;
a = new Array(1,2,3);
b = "JScript";
c = new Array(42, "VBScript);
a.concat(b, c);
Return array [1, 2, 3, "JScript", 42, "VBScript"]
return(d);
}