Array扩展方法:

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

 

调用方式:

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

 

相关文章: