JavaScript Array unshift()
Example
Add new items to the beginning of an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");
Try it Yourself »
Definition and Usage
The unshift() method adds new items to the beginning of an array, and returns the new length.
unshift() overwrites the original array.
Tip: To add new items at the end of an array, use push().
Browser Support
unshift() is fully supported in all browsers:
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
array.unshift(item1, item2, ..., itemX)
Parameter Values
| Parameter | Description |
|---|---|
| item1, item2, ..., itemX | Required. The item(s) to add to the beginning of the array |
Technical Details
| Return Value: | A Number, representing the new length of the array |
|---|---|
| JavaScript Version: | ECMAScript 1 |

