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

Array.prototype.push() β€” push multiple values

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

Pass multiple arguments to push() to append several elements in one call.

Array.prototype.push() β€” multiple arguments

push() accepts multiple arguments and appends all of them in order.

const arr = [1]
arr.push(2, 3, 4) // returns 4, arr === [1, 2, 3, 4]
πŸ’‘ Hints (2)
  • β€’ Use the spread operator to forward all rest params: `arr.push(...vals)`.
  • β€’ Rest parameters (`...vals`) collect all extra arguments into an array.