JavaScript push()Method
Example
Add a new element to the array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi")
fruits.push("Kiwi")
fruitsOutput:
Banana,Orange,Apple,Mango,Kiwi
Try it Yourself »
Definition and Usage
The push() method adds one or more elements to the end of an array and returns the new length.
Note:New elements are added at the end of the array.
Note:This method changes the length of the array.
Tip:To add elements at the beginning of an array, use theunshift()method.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support push().
Syntax
array.push(item1, item2, ..., itemX)
Parameter Values
| Parameter | Description |
|---|---|
| item1, item2, ..., itemX | Required. The element(s) to add to the array. |
Return Value
| Type | Description |
|---|---|
| Number | The new length of the array |
Technical Details
| JavaScript Version: | 1.2 |
|---|
More Examples
Example
Add more than one element
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi","Lemon","Pineapple")
fruits.push("Kiwi","Lemon","Pineapple")
The example above will output
Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple
Try it Yourself »
Other Extensions
JavaScript Array Object