代码收藏

收集网站开发时常用到的代码(asp,php,js等)

« iscn-判断是否有包括中文的字符串JS读取写入Cookies操作 »

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;
}

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80605

Copyright 2008 ITlearner. Some Rights Reserved.