源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>删除元素在数组中留下未定义的"洞".</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo").innerHTML = fruits; function myFunction() { delete fruits[0]; document.getElementById("demo").innerHTML = fruits[0]; } </script> </body> </html>
运行结果