There is method to add elements at the beginning of an array using unshift method
The array unshift method adds element at the beginning of an array and returns its new length. This method can be applied to the objects that resembles an array.
Syntax :- array.unshift(item1, item2, ..., itemX)
Below is the example code :
var arr = [hello, everyone];
arr.unshift(hi); // result of call is hi, the new array length
// arr is [hi, hello, everyone]
arr.unshift(you, me); //
// arr is [you, me, hi, hello, everyone]
arr.unshift([party]);
// arr is [[party], you, me, hi, hello, everyone]
0 Comment(s)