<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Javascript自定义数组删除方法remove()</title> <script type="text/javascript"> Array.prototype.remove=function(dx){ if(isNaN(dx)||dx>this.length){return false;} for(var i=0,n=0;i<this.length;i++){ if(this[i]!=this[dx]){ this[n++]=this[i] } } this.length-=1 } function f(){ var str = "001|002|003";// var arr = str.split("|"); alert("删除前数组长度:" + arr.length); for(var i=0;i<arr.length;i++){ alert(arr[i]); } arr.remove(1);//javascript本来是不包含些函数的。 alert("删除后数组长度:" + arr.length); for(var i=0;i<arr.length;i++){ alert(arr[i]); } } </script> </head> <body> <input type="button" onclick="f();" value="ok" /> </body> </html>
For more articles related to Javascript remove custom array deletion method, please pay attention to the PHP Chinese website!