JavaScript concat()Method
Example
Concatenate the values of three arrays:
var a = ["Google", "Taobao"];
var b = ["Example", "Wiki", "Zhihu"];
var c = a.concat(b);
document.write(c);
childrenOutput:
Google,Taobao,Example,Wiki,Zhihu
Try it Yourself »
Definition and Usage
The concat() method is used to concatenate two or more arrays.
This method does not change the existing arrays, but returns a new array.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the concat() property.
Syntax
array1.concat(array2, array3,..., arrayX)
Parameters
| Parameters | Description |
|---|---|
| array2, array3,..., arrayX | Required. The array to concatenate. |
Return Value
| Type | Description |
|---|---|
| Array object | Returns a new array. This array is generated by adding all arrayX parameters to arrayObject. If the parameter to the concat() operation is an array, the elements in the array are added, not the array itself. |
Technical Details
| JavaScript Version: | 1.2 |
|---|
More Examples
The following example uses the concat() method to add the elements of array2 to the end of array1, and returns a new array containing all the elements of array1 and array2.
Example
Concatenate two arrays:
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3); //Output: ['a', 'b', 'c', 'd', 'e', 'f']
childrenOutput:
['a', 'b', 'c', 'd', 'e', 'f']
Try it Yourself »
The following example uses the concat() method to add the elements of array2 and array3 to the end of array1, and returns a new array.
Example
Concatenate three arrays:
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = ['g', 'h', 'i'];
const array4 = array1.concat(array2, array3);
console.log(array4); //Output: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
childrenOutput:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
Try it Yourself »
Other Extensions
JavaScript Array Object