Easy Tutorial
❮ Coll Table Tbodies Prop Style Perspectiveorigin ❯

JavaScript unshift() Method

JavaScript Array Object

Example

Add new items to the beginning of an array:

fruits will output:

Lemon,Pineapple,Banana,Orange,Apple,Mango

Definition and Usage

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

Note: This method will change the length of the array.

Tip: To add new items to the end of an array, use the push() method.


Browser Support

All major browsers support the unshift() method, except Internet Explorer 8 and earlier versions.

Note: The unshift() method returns undefined in Internet Explorer 8 and earlier versions.


Syntax

Parameter Values

Parameter Description
item1, item2, ..., itemX Optional. One or more elements to add to the beginning of the array.

Return Value

Technical Details

| JavaScript Version: | 1.2 | | --- | --- |


JavaScript Array Object

❮ Coll Table Tbodies Prop Style Perspectiveorigin ❯