Array.prototype.removeBeginWithVal(删除数组内以某值开头的字符串对象)

时间:2022-12-14 10:18:00

Array扩展方法:

 //author: Kenmu
//created time: 2015-03-16
//function: 删除数组内以某值开头的字符串对象
Array.prototype.removeBeginWithVal = function (val) {
for(var i=0, len = this.length; i < len; i++) {
if(this[i].indexOf(val) != -1) {
this.splice(i, 1);
break;
}
}
};

调用方式:

 var arr =["Kenmu", "DemandTypeStringCode"];
arr.removeBeginWithVal("DemandTypeStringCode"); //arr.length=1 after the operation of removeBeginWithVal