JavaScript: Array.prototype.push

By Xah Lee. Date: . Last updated: .
arrayX.push(new1, new2 etc)
Adds items to the end of the array arrayX. Return the new length.
const ar = [3];
console.log( ar.push(7, [8]) ); // 3
console.log( ar ); // [ 3, 7, [ 8 ] ]

To join arrays by flattening 1 level, see Array.prototype.concat .

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