Latest web development tutorials

JavaScript push () method

Array Object Reference JavaScript Array Object

Examples

Add a new element in the array:

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

fruits resulting output:

Banana,Orange,Apple,Mango,Kiwi

try it"

Definition and Usage

push () method to add one or more elements to the end of an array and returns the new length.

Note: The new element is added at the end of the array.

NOTE: This method changes the length of the array.

Tip: In the beginning of the array to add elements using the unshift () method.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support push ().


grammar

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

Parameter Value

参数 描述
item1 , item2 , ..., itemX 必需。要添加到数组的元素。

return value

类型 描述
Number 数组新长度

technical details

JavaScript version: 1.2


More examples

Examples

Adding more than one element

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

The above examples will output

Banana,Orange,Apple,Mango,Kiwi,Lemon,Pineapple

try it"

Array Object Reference JavaScript Array Object