JavaScript Array unshift()
Example
Add new elements to an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");
Try it Yourself »
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. |
Return Value
Type | Description |
A number | The new length of the array. |
Related Pages:
Browser Support
unshift()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.