`

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

阅读更多

//判断数组中是否存在某字符串
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。

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics