The unshift() method adds new items to the beginning of an array, and returns the new length.
The unshift() method adds new items to the beginning of an array, and returns the new length.
This method changes the length of an array.
You can add new items at the end of an array, use the push() method.
array.unshift(item1,item2, ...,itemX)
Parameter | Require | Description |
---|---|---|
item1, item2, ..., itemX | Required. | The item(s) to add to the beginning of the array |
A Number, representing the new length of the array
Add new items to the beginning of an array:
var myArray = ["XML", "Json", "Database", "Mango"]; console.log( myArray );// w ww . ja v a 2 s . co m myArray.unshift("Lemon", "PineDatabase"); console.log( myArray );