+ 3
How to use the unshift in javascript?
javascript unshift
3 Réponses
+ 8
var arr=[6,5,2];
arr=arr.unshift(3);
alert(arr);
//3,6,5,2
the unshift() method pushes an element into an array's first index
it is the opposite of push() which pushes an element into an array's last index
+ 4
Hello, Ronalyn Joy Sardañas !
This method changes the original array.
Adds arguments to it and returns the resulting length.
var arrOne = ["a", "b"]
var unshiftedOne = arrOne.unshift(-2, -1);
alert(arr); // [-2, -1, "a", "b"]
alert("New length:" + unshiftedOne); // 4