JavaScript concat() Method
Example
Merge the values of three arrays:
var
a
=
[
"
"
,
"
Taobao
"
]
;
var
b
=
[
"
Runoob
"
,
"
Wiki
"
,
"
Zhihu
"
]
;
var
c
=
a
.
concat
(
b
)
;
document
.
write
(
c
)
;
children Output result:
Google,Taobao,Runoob,Wiki,Zhihu
Try it »
Definition and Usage
The concat() method is used to join two or more arrays.
This method does not change the existing array, 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(s) to be concatenated. |
Return Value
| Type | Description |
|---|---|
| Array object | Returns a new array. This array is generated by adding all the arrayX parameters to arrayObject. If the parameter to be concatenated is an array, its elements are added rather than the array itself. |
Technical Details
| JavaScript version: | 1.2 |
|---|
More examples
The following example uses the concat() method to append the elements of array2 to the end of array1 and returns a new array containing all the elements of array1 and array2.
Example
Merge 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']
children Output result:
['a', 'b', 'c', 'd', 'e', 'f']
Try it »
The following example uses the concat() method to append the elements of both array2 and array3 to the end of array1 and returns a new array.
Example
Merge 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']
children Output result:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
Try it »
JavaScript Array object