如果你没有使用第三方框架,有类似的扩展功能可以根据指定值,返回元素的下标的话,只能自己先查找,然后再删除。
<script type="text/javascript">
Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
var array = [1, 2, 3, 4, 5];
array.remove(3);
</script>
Array.prototype.remove=function(){
var what, a= arguments, L= a.length, ax;
while(L &&this.length){
what= a[--L];
while((ax=this.indexOf(what))!=-1){
this.splice(ax,1);
}
}
returnthis;
}
var ary =['three','seven','eleven'];
ary.remove('seven')
/* returned value: (Array)
three,eleven
*/