JavaScript Array unshift()
Example
Add new elements to an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");
Try it Yourself »
fruits.unshift("Lemon","Pineapple");
Description
The unshift() method adds new elements to the beginning of an array.
The unshift() method overwrites the original array.
Syntax
array.unshift(item1, item2, ..., itemX)
Parameters
Type
Description
item1
item2
..
itemX The item(s) to add to the array.
Minimum one item is required.
item2
..
itemX The item(s) to add to the array.
Minimum one item is required.
Return Value
Type
Description
A number The new length of the array.
Array Tutorials:
Browser Support
unshift() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |