X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Array push() Method

JavaScript Array Reference 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 JavaScript Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook