JS中我们可以通过pop方法移除数组的最后一个元素,可以通过shift方法移除数组的第一个元素
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to remove the first element of the array.</p>
<button onclick="myFunction()">Try it</button>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
function myFunction()
{
fruits.shift();
var x=document.getElementById("demo");
x.innerHTML=fruits;
}
</script>
</body>
</html>
上面的代码输出如下结果
Orange,Apple,Mango
