ITeye博客

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

可怜的猫 · 2016-02-01 15:07 · web前端 · Web前端 · js 数组 · Markdown

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

暂无评论。

评论功能维护中,当前仅展示历史评论。