将一下代码放在全局js文件中:
Js代码
/**
*删除数组指定下标或指定对象
*/
Array.prototype.remove=function(obj){
for(var i =0;i var temp = this[i];
if(!isNaN(obj)){
temp=i;
}
if(temp == obj){
for(var j = i;j this[j]=this[j+1];
}
this.length = this.length-1;
}
}
}
使用方法:
Js代码
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”