JS: Array.prototype.concat

By Xah Lee. Date: . Last updated: .
xArray.concat(new1, new2, etc)
  • add items to the end of array.
  • Return a new array.
  • Each argument can be any type.
  • If an argument is a array, it is flattened 1 level.
console.log([1].concat(2));
// [ 1, 2 ]
// if arg is an array, it is flattened 1 level
console.log([1].concat([2, [3]]));
// [ 1, 2, [ 3 ] ]

JavaScript. Add or Remove Subarray