JavaScript Array push() Method
Example
Add a new item to an array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The push() method adds new items to the end of an array, and returns the new length.
Note: The new item(s) will be added at the end of the array.
Note: This method changes the length of the array.
Tip: To add items at the beginning of an array, use the unshift() method.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
push() | 1.0 | 5.5 | 1.0 | Yes | Yes |
Syntax
array.push(item1, item2, ..., itemX)
Parameter Values
Parameter | Description |
---|---|
item1, item2, ..., itemX | Required. The item(s) to add to the array |
Technical Details
Return Value: | A Number, representing the new length of the array | Try it » |
---|---|---|
JavaScript Version: | ECMAScript 1 |
More Examples
Example
Add more than one item:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple");
Try it Yourself »
Related Pages
JavaScript Tutorial: JavaScript Arrays
JavaScript Tutorial: JavaScript Array Methods
JavaScript Reference: JavaScript pop() Method
JavaScript Reference: JavaScript shift() Method