首页 > 编程语言 > 详细

JS 判断数组中是否存在某字符串

时间:2016-02-02 02:10:26      阅读:184      评论:0      收藏:0      [点我收藏+]

//判断数组中是否存在某字符串
Array.prototype.S=String.fromCharCode(2);
Array.prototype.in_array=function(e){
??? var r=new RegExp(this.S+e+this.S);
??? return (r.test(this.S+this.join(this.S)+this.S));
};

?

用法:

????var arr = [‘a‘,‘b‘,‘c‘];

??? arr.in_array("a");//返回值为true或false。存在为true,不存在为false。

JS 判断数组中是否存在某字符串

原文:http://lafecat.iteye.com/blog/2275272

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