JavaScript Array push() Method
- Previous Page prototype
- Next Page reduce()
- Go Up One Level JavaScript Array Reference Manual
Definition and Usage
push()
The method adds a new item to the end of the array and returns the new length.
Tip:The new item will be added to the end of the array.
Note:push()
The method changes the length of the array.
Tip:To add items to the beginning of an array, use unshift()
Method.
Example
Example 1
Add a New Item to the Array:
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi");
Example 2
Add Multiple Items:
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi", "Lemon", "Pineapple");
Example 3
push() Returns the New Length:
const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi"); // Returns 5
Syntax
array.push(item1, item2, ... , itemX)
Parameter Value
Parameter | Description |
---|---|
item1, item2, ..., itemX | Required. The item to be added to the array. |
Technical Details
Return Value: | A number, representing the new length of the array. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
The numbers in the table indicate the first browser version that fully supports this method.
All browsers fully support push()
Method:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Array
Tutorial:JavaScript Array Const
Tutorial:JavaScript Array Methods
Tutorial:JavaScript Array Sorting
Tutorial:JavaScript Array Iteration
Manual:JavaScript pop() Method
Manual:JavaScript shift() Method
Manual:JavaScript unshift() Method
- Previous Page prototype
- Next Page reduce()
- Go Up One Level JavaScript Array Reference Manual