javascript模拟php函数in_array_javascript技巧
来源:懂视网
责编:小采
时间:2020-11-27 21:37:37
javascript模拟php函数in_array_javascript技巧
javascript模拟php函数in_array_javascript技巧:js 中判断某个元素是否存在于某个 js 数组中,相当于 php 语言中的 in_array 函数。 Array.prototype.S=String.fromCharCode(2); Array.prototype.in_array=function(e){ var r=new RegExp(this.S+e+this.S
导读javascript模拟php函数in_array_javascript技巧:js 中判断某个元素是否存在于某个 js 数组中,相当于 php 语言中的 in_array 函数。 Array.prototype.S=String.fromCharCode(2); Array.prototype.in_array=function(e){ var r=new RegExp(this.S+e+this.S

js 中判断某个元素是否存在于某个 js 数组中,相当于 php 语言中的 in_array 函数。
用法如下:
注:此函数只对字符和数字有效
jQuery中有类似的函数:http://docs.jquery.com/Utilities/jQuery.inArray
它的代码如下:
javascript模拟php函数in_array_javascript技巧
javascript模拟php函数in_array_javascript技巧:js 中判断某个元素是否存在于某个 js 数组中,相当于 php 语言中的 in_array 函数。 Array.prototype.S=String.fromCharCode(2); Array.prototype.in_array=function(e){ var r=new RegExp(this.S+e+this.S