splice从数组中删除指定定数据

/*
从数组中删除指定定数据
var somearray = ["mon", "tue", "wed", "thur"]
somearray.removeByValue("tue");
//somearray will now have "mon", "wed", "thur"
*/
Array.prototype.removeByValue = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) {
this.splice(i, 1);
break;
}
}
}

 

posted on 2016-05-21 14:39  Frank-  阅读(2362)  评论(0编辑  收藏  举报

导航