此方法用于从数组中删除元素。此外,此方法与之不同,pop()
因为shift()
方法是在数组的开头删除元素。
<html> <body> <p id="shift"></p> <script> var a = [1,2,3,4,5]; var b = ["apple","mango","banana","guava","strawberry"] a.shift(); b.shift(); document.write(a); document.getElementById("shift").innerHTML = b; </script> </body> </html>
mango,banana,guava,strawberry 2,3,4,5