删除数组中的第一个元素 - shift()
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 数组方法</h1>
- <h2>shift()</h2>
- <p>shift() 方法删除数组的第一个元素(并将所有其他元素“移位”到左侧):</p>
- <p id="demo1"></p>
- <p id="demo2"></p>
- <script>
- var fruits = ["Banana", "Orange", "Apple", "Mango"];
- document.getElementById("demo1").innerHTML = fruits;
- fruits.shift();
- document.getElementById("demo2").innerHTML = fruits;
- </script>
- </body>
- </html>