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

ParameterDescription
elements The elements to add.

Return value

The new length.

Examples

Add to the endTry it yourself
const cart = ["tea"];
const newLength = cart.push("cake", "jam");
console.log(cart, newLength);

Output

[ 'tea', 'cake', 'jam' ] 3
Push all elements of another arrayTry it yourself
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

VersionChange
JavaScript ES3Added

In other languages