标签:
/*
从数组中删除指定定数据
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;
}
}
}
/*
判断数组中是否存在
var somearray = ["mon", "tue", "wed", "thur"]
somearray.exists ("tue");
//somearray will return true
*/
Array.prototype.exists = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) {
return true;
}
}
return false;
}
标签:
原文地址:http://www.cnblogs.com/wu-peng/p/5514732.html