JavaScript unshift () method
Examples
Add a new item to the beginning of the array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");
fruits.unshift("Lemon","Pineapple");
fruits will output:
Lemon, Pineapple, Banana, Orange, Apple, Mango
try it"
Definition and Usage
unshift () method to add one or more elements to the beginning of an array and returns the new length.
Note: This method will change the number of the array.
Tip: add a new item to the end of the array, use the push () method.
Browser Support
All major browsers support unshift () method, Internet Explorer 8 and earlier versions do not support IE.
Note: unshift () method in Internet Explorer 8 and earlier versions of IE returns undefined.
grammar
array.unshift( item1 , item2 , ..., itemX )
Parameter Values
参数 | 描述 |
---|---|
item1 , item2 , ..., itemX | 可选。向数组起始位置添加一个或者多个元素。 |
return value
technical details
JavaScript version: | 1.2 |
---|