Array.prototype.remove=function(obj){ for(var i =0;i <this.length;i++){ var temp = this[i]; if(!isNaN(obj)){ temp=i; } if(temp == obj){ for(var j = i;j <this.length;j++){ this[j]=this[j+1]; } this.length = this.length-1; } } }
使用方法this
var arr =new Array(); arr[0]="dddddd"; arr[1]="dxxxxxxx"; arr[2]="vvvvvvv"; arr[3]="dbbbbb"; var str ="vvvvvvv"; arr.remove(3);//刪除下標爲3的對象 arr.remove(str);//刪除對象值爲「vvvvvvv」