+ 3

How to use the unshift in javascript?

javascript unshift

7th Jul 2018, 6:42 AM
Ronalyn Joy Sardañas
Ronalyn Joy Sardañas - avatar
3 ответов
7th Jul 2018, 6:47 AM
Igor Makarsky
Igor Makarsky - avatar
+ 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
7th Jul 2018, 6:53 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 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
7th Jul 2018, 6:53 AM
Alexander Sokolov
Alexander Sokolov - avatar