<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用splice()实现数组的增删改查</title> </head> <body> <script> // 语法:arrayObject.splice(index,howmany,item1,.....,itemX) var arr=['html','css','php','TP6.0']; arr.splice(2,0,'javascript'); //在键值为2的前面删除了0个属性值,增加了‘javascript’ arr.splice(1,1); //删除了‘css’ arr.splice(3,1,'TP5.1'); //把TP6.0改成了TP5.1 document.write(arr); //把结果输出到浏览器上显示 </script> </body> </html>
点击 "运行实例" 按钮查看在线实例