JS Built-ins
← Array142 / 226
ArrayArray.prototype.pushbeginner

Array.prototype.push() β€” add to end

πŸ“– Usage Example
const arr = [1, 2]
arr.push(3)  // returns 3 (new length)
arr  // β†’ [1, 2, 3]

Use push() to add one element to the end of an array and get the new length.

Array.prototype.push()

push() appends one or more elements to the end of an array and returns the new length of the array.

const arr = [1, 2]
const newLen = arr.push(3) // newLen === 3, arr === [1, 2, 3]
πŸ’‘ Hints (2)
  • β€’ `push` returns the new length of the array, not the pushed element.
  • β€’ You can directly return the result of `arr.push(val)`.