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。

猜你喜欢

转载自lafecat.iteye.com/blog/2275272
今日推荐