简单教程
提交运行
代码编辑器:
<p id="demo">单击按钮删除数组的第一个元素</p> <p id="demo2"></p> <button onclick="myFunction()">点我</button> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; function myFunction(){ var delell = fruits.shift(); var x=document.getElementById("demo"); x.innerHTML= '删除后数组为:' + fruits; document.getElementById("demo2").innerHTML= '删除的元素是:' + delell; } </script>
运行结果: