JS: Array.prototype.unshift

By Xah Lee. Date: . Last updated: .

arrayX.unshift(new1, new2 etc)

Adds items to the beginning of array arrayX.

Return the new length.

arrayX is modified.

// example of using array.unshift()
const ar = [3,4];

console.log (
    ar.unshift(7, [8], 9)
); // 5

console.log (
    ar
);   // [7, [ 8 ], 9, 3, 4]

Buy JavaScript in Depth

JavaScript in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype