首页 > 编程语言 > 详细

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

时间:2015-05-28 17:53:04      阅读:298      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:http://www.cnblogs.com/huangjianwu/p/4536432.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!