English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
array.push(element1, ..., elementN
var fruits = ["Banana", "Mango", "Apple"]; fruits.push("Strawberry");Test and see‹/›
The numbers in the table specify the first browser version that fully supports the push() method:
Method | |||||
push() | Yes | 1.5 | Yes | Yes | 9 |
Parameter | Description |
---|---|
elementN | Element to be added to the end of the array |
Return Value: | Returns the new length of the array |
---|---|
JavaScript Version: | ECMAScript 1 |
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