JavaScript: Array.prototype.concat

By Xah Lee. Date: . Last updated: .
arrayX.concat(new1, new2 etc)
Return a new array by joining arguments to the array. Each argument can be any type. If it is a array, it will be flattened 1 level (That is, remove the outmost brackets).
// example of using array.concat()

const mya = [1];

console.log( mya.concat( 2, [3], {k9:9}) );
// [ 1, 2, 3, { k9: 9 } ]

console.log( mya );
// [1]

To add without flatten, use push. See: Array.prototype.push .

For how to flatten nested array, see: Array.prototype.flat .

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype