如题所述
js中判断某个元素是否存在于某个js数组中,相当于php语言中的in_array函数。Array.prototype.S=String.fromCharCode(2);Array.prototype.in_array=function(e){varr=newRegExp(this.S+e+this.S);return(r.test(this.S+this.join(this.S)+this.S));};用法如下:vararr=newArray();arr.in_array('test');//判断test字符串是否存在于arr数组中,存在返回true否则false注:此函数只能对字符和数字有效
温馨提示:答案为网友推荐,仅供参考