Array.prototype.concat()
Merges two or more arrays into a new array.
Syntax
arr.concat(...values) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
values | any | No | Arrays or values to concatenate. Arrays are flattened one level; non-array values are appended as-is. |
Returns
Array — A new array consisting of the elements of the source and the arguments.
Examples
console.log([1, 2].concat([3, 4], 5));
Output
[ 1, 2, 3, 4, 5 ]
console.log([1].concat([[2]]));
Output
[ 1, [ 2 ] ]
Notes
Does not mutate any of the source arrays. Only flattens one level; nested
arrays stay nested. The spread operator `[...a, ...b]` is a common alternative.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |