in_array – js模拟php中的in_array

in_array

in_array — 检查数组中是否存在某个值
说明
bool in_array ( mixed needle, array haystack [, bool strict] )

在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。

function in_array(needle, haystack) {
if(typeof needle == 'string' || typeof needle == 'number') {
for(var i in haystack) {
if(haystack[i] == needle) {
return true;
}
}
}
return false;
}

Popularity: 7%

No Responses to “in_array – js模拟php中的in_array”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>