X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET 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 »


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

Internet Explorer Firefox Opera Google Chrome Safari

The push() method is supported in all major browsers.


Syntax

array.push(item1, item2, ..., itemX)

Parameter Values

Parameter Description
item1, item2, ..., itemX Required. The item(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 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