JavaScript (ES2026) reference · Array Methods
JavaScript Array push() Method
Add one or more elements to the end of the array and return the new length. Changes the array in place.
JavaScript (ES2026) Since ES3
Syntax
array.push(element1, /* …, */ elementN)
Parameters
| Parameter | Description |
|---|---|
elements |
The elements to add. |
Return value
The new length.
Examples
const cart = ["tea"];
const newLength = cart.push("cake", "jam");
console.log(cart, newLength);
Output
[ 'tea', 'cake', 'jam' ] 3
const a = [1, 2];
a.push(...[3, 4]); // add every element of another array
console.log(a);
Output
[ 1, 2, 3, 4 ]
push() returns the new length, not the array, so don't chain array methods after it.
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
In other languages
list.append()· Python
Related
array.pop()· Remove the last element from the array and return it. Changes the array; returns undefined if it is empty.array.unshift()· Add one or more elements to the start of the array and return the new length. Changes the array in place.array.concat()· Return a new array that joins this array with other arrays or values. The original arrays are not changed.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial