源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>shift方法移除数组的第一个元素, 并且“转移”所有其他元素另一个地方.</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo").innerHTML = fruits; function myFunction() { fruits.shift(); document.getElementById("demo").innerHTML = fruits; } </script> </body> </html>
运行结果