Array.prototype.concat

Returns a new array created by concatenating the current array with the given arrays.

Syntax

concat(...arrays)

Parameters

Return value

Returns an array that contains every element of the current array and every element of the arrays that were passed to the function in the order they were passed.

Remarks

The function doesn’t change the original or any of the passed arrays, it returns a new array.

Examples

[1, 2, 3].concat([4, 5, 6])
[ 1, 2, 3, 4, 5, 6 ]
[1, 2, 3].concat([4, 5, 6], [7, 8])
[ 1, 2, 3, 4, 5, 6, 7, 8 ]
let x = ["A", "B"]
let y = ["C", "D"]
let z = ["E", "F", "G"]
let all = x.concat(y, z)
all
["A", "B", "C", "D", "E", "F", "G"]
Array.prototype.concat.call([1, 2], [3, 4], [5, 6])
[ 1, 2, 3, 4, 5, 6 ]