Easy Tutorial
❮ Prop Checkbox Defaultchecked Prop Style Clear ❯

JavaScript push() Method

JavaScript Array Object

Example

Adding new elements to an array:

fruits result output:


Definition and Usage

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

Note: New elements will be added at the end of the array.

Note: This method changes the length of the array.

Tip: To add elements at the beginning of the array, use the unshift() method.


Browser Support

All major browsers support the push() method.


Syntax

Parameter Values

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

Adding more than one element

The above example will output


JavaScript Array Object

❮ Prop Checkbox Defaultchecked Prop Style Clear ❯