English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array push() Method

 JavaScript Array Object

push()The method adds one or more elements to the end of the array and returns the new length of the array.

Note:To add an element to the beginning of an array, please useunshift()Method.

Syntax:

array.push(element1, ..., elementN
var fruits = ["Banana", "Mango", "Apple"];
fruits.push("Strawberry");
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the push() method:

Method
push()Yes1.5YesYes9

Parameter Value

ParameterDescription
elementNElement to be added to the end of the array

Technical Details

Return Value:Returns the new length of the array
JavaScript Version:ECMAScript 1

More Examples

The following code appends three elements to the array. The total variable contains the new length of the array:

var fruits = ["Banana", "Mango", "Apple"];
var total = fruits.push("Strawberry", "Lychee", "Guava");
Test and see‹/›

The following code appends the value of the input field to the array:


Banana, Mango, Apple

 JavaScript Array Object