References

Beginner-friendly references for web development, with live, editable examples.

The JavaScript array.push() method

Method JavaScript All modern browsers Updated
Quick answer

The push() method adds one or more elements to the end of an array and returns the array's new length. const a = [1, 2]; a.push(3) makes a become [1, 2, 3]. It changes the original array in place — that's the key difference from map() and concat(), which return new arrays.

Overview

push() appends elements to the end of an array. Pass it one value or several, and they're all tacked on in order. It's the everyday way to grow a list — collecting results in a loop, adding an item to a cart, building up a log. The return value is the new length, not the array itself, which trips people up the first time.

Crucially, push() mutates the array it's called on rather than returning a new one. That's usually what you want for performance and simplicity, but it matters in code that avoids mutation — React state, for instance, where you'd use the spread syntax ([...arr, item]) to make a new array instead.

To add to the start of an array, use unshift(); to remove from the end, use pop(). Together push() and pop() turn an array into a stack. If you need a new array rather than a mutation, concat() or the spread operator is the immutable alternative.

Syntax

const newLength = array.push(element1)
const newLength = array.push(element1, element2, /* ... */ elementN)

Parameters

The array.push() method accepts the following parameters.

Parameter Description
element1 ... elementN One or more values to append to the end of the array, in order.

Example

Live example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
  const stack = ['a', 'b'];

  const len = stack.push('c', 'd');

  document.getElementById('out').textContent =
    'array:  ' + stack.join(', ') + '\n' +
    'length: ' + len; // array: a, b, c, d / length: 4
</script>

Best practices

  • Remember push() returns the new length, not the array — don't write arr = arr.push(x).
  • Push several items at once — arr.push(a, b, c) — rather than calling push() repeatedly.
  • It mutates the array; in code that avoids mutation (like React state) use the spread syntax [...arr, item] instead.
  • Pair it with pop() for stack behavior, or unshift()/shift() to work at the front.

Frequently asked questions

What does push() return in JavaScript?
The new length of the array after adding the elements — not the array itself.
Does push() change the original array?
Yes. push() mutates the array in place. To get a new array instead, use concat() or the spread operator [...arr, item].
How do I add multiple items with push()?
Pass them as separate arguments: arr.push(a, b, c). To append a whole array, spread it: arr.push(...other).
How do I add an item to the start of an array?
Use unshift() instead of push(). It adds to the front and also returns the new length.