push()

ES3+

Adds one or more elements to the end of an array and returns the new length.

Syntax

array.push(element1, element2, ...)

Parameters

elements any

Elements to add to the end of the array

Return Value

number

The new length of the array

Examples

JavaScript
const fruits = ['apple', 'banana'];
const newLength = fruits.push('cherry');
console.log(fruits);
console.log(newLength);
Output:
// ['apple', 'banana', 'cherry'] 3

Related Methods