900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > JavaScript判断数组是否包含指定元素办法【javascript】

JavaScript判断数组是否包含指定元素办法【javascript】

时间:2020-04-25 00:04:34

相关推荐

JavaScript判断数组是否包含指定元素办法【javascript】

web前端|js教程

JavaScript,数组,包含,元素

web前端-js教程

本文实例讲述了JavaScript判断数组是否包含指定元素的方法。分享给大家供大家参考。具体如下:

打码网源码,vscode文件在浏览器运行,ubuntu 淘宝源,tomcat加启动参数配置,细长脚爬虫,国产php开发框架,seo综合查询湖南岚鸿广告lzw

这段代码通过prototype定义了数组方法,这样就可以在任意数组调用contains方法

头像抽奖源码,vscode 目录插件,ubuntu 中,tomcat讲解视频,微信 sqlite 开源,jquery html5 上传插件,h5演示前端框架,python爬虫实例200例,php5.2 linux,苏州seo营销费用,帝国软件怎么发布网站,网页实现提醒,jquery 模板下载lzw

/** * Array.prototype.[method name] allows you to define/overwrite an objects method * needle is the item you are searching for * this is a special variable that refers to "this" instance of an Array. * returns true if needle is in the array, and false otherwise */Array.prototype.contains = function ( needle ) { for (i in this) { if (this[i] == needle) return true; } return false;}

用法:

vpn局部代理源码,vscode用户字符串实例,ubuntu 看图工具,iis tomcat那个好,爬虫 图片 重复,php升级培训,韶关服务好的seo怎样做lzw

// Now you can do things like:var x = Array();if (x.contains(foo)) { // do something special}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。