Array.prototype.push()

push(...items)
Returns: number · Added in vES5 · Updated March 13, 2026 · Array Methods
array push mutating

push() adds one or more elements to the end of an array and returns the new length of the array. It modifies the array in place.

Syntax

arr.push(element1)
arr.push(element1, element2)
arr.push(element1, element2, /* ... */ elementN)

Parameters

ParameterTypeDefaultDescription
itemsanyThe element(s) to add to the end of the array. Accepts multiple arguments.

Examples

Basic usage

const fruits = ["apple", "banana"];

const newLength = fruits.push("cherry");
console.log(fruits);    // ["apple", "banana", "cherry"]
console.log(newLength); // 3

Adding multiple elements

const nums = [1, 2, 3];
const newLength = nums.push(4, 5, 6);
console.log(nums);      // [1, 2, 3, 4, 5, 6]
console.log(newLength); // 6

Using push with zero arguments

const arr = [1, 2, 3];
const length = arr.push();
console.log(length); // 3 (no change)

Common Patterns

Building an array dynamically

const results = [Global_Objects::eval];
for (let i = 0; i < 5; i++) {
  results.push(i * 2);
}
console.log(results); // [0, 2, 4, 6, 8]

Queue with push (and shift for dequeue)

class Queue {
  constructor() {
    this.items = [Global_Objects::eval];
  }
  
  enqueue(item) {
    this.items.push(item);
  }
  
  dequeue() {
    return this.items.shift();
  }
  
  peek() {
    return this.items[0];
  }
}

const queue = new Queue();
queue.enqueue("first");
queue.enqueue("second");
console.log(queue.dequeue()); // "first"

Converting iterable to array

const str = "hello";
const chars = [Global_Objects::eval];
for (const char of str) {
  chars.push(char);
}
console.log(chars); // ["h", "e", "l", "l", "o"]

Behavior Notes

  • push() accepts zero arguments, which returns the current length without changes
  • This method modifies the original array (mutating method)
  • Returns the new length of the array, not the added elements

See Also