<div class="codetitle"> <span><a style="CURSOR: pointer" data="60134" class="copybut" id="copybut60134" onclick="doCopy('code60134')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code60134"> <br> <br> <br><title>Javascript自定义数组删除方法remove()</title> <br><script type="text/javascript"> <BR> Array.prototype.remove=function(dx){ <BR> if(isNaN(dx)||dx>this.length){return false;} <BR> for(var i=0,n=0;i<this.length;i++){ <BR> if(this[i]!=this[dx]){ <BR> this[n++]=this[i] <BR> } <BR> } <BR> this.length-=1 <BR> } <BR>function f(){ <BR>var str = "001|002|003";// <BR>var arr = str.split("|"); <BR>alert("删除前数组长度:" + arr.length); <BR>for(var i=0;i<arr.length;i++){ <BR>alert(arr[i]); <BR>} <BR>arr.remove(1);//javascript本来是不包含些函数的。 <BR>alert("删除后数组长度:" + arr.length); <BR>for(var i=0;i<arr.length;i++){ <BR>alert(arr[i]); <BR>} <BR>} <BR></script> <br> <br> <br><input type="button" onclick="f();" value="ok"> <br> <br> <br> </div>