<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <p id="demo0">删除最后一个元素</p> <p id="demo1">数组最后添加一个元素</p> <p id="demo2">指定索引添加元素</p> <p id="demo3">指定索引删除元素</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var arr0 = ["1", "2", "3", "4"]; arr0.pop(); document.getElementById("demo0").innerHTML = arr0; var arr1 = ["1", "2"]; arr1.push("3"); document.getElementById("demo1").innerHTML = arr1; var arr2 = ["1", "3"]; arr2.splice(1, 0, "2"); document.getElementById("demo2").innerHTML = arr2; var arr3 = ["1", "4", "2", "3"]; arr3.splice(1, 1); document.getElementById("demo3").innerHTML = arr3; } </script> </body> </html>