Latest web development tutorials
 

JavaScript Array push() Method

< JavaScript Array Reference

Example

Add a new item to an array:

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

The result of fruits will be:

Banana,Orange,Apple,Mango,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
JavaScript Version: 1.2

Examples

More Examples

Example

Add more than one item:

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

The output of the code above will be:

Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple
Try it Yourself »

< JavaScript Array Reference