JavaScript Array push() Method

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");

Try It Yourself

Example 2

Add Multiple Items:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi", "Lemon", "Pineapple");

Try It Yourself

Example 3

push() Returns the New Length:

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");   // Returns 5

Try It Yourself

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