国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

JavaScri-pt判斷數組是否包含指定元素的方法

2019-11-02 14:24:27
字體:
來源:轉載
供稿:網友

   本文實例講述了JavaScript判斷數組是否包含指定元素的方法。分享給大家供大家參考。具體如下:

  這段代碼通過prototype定義了數組方法,這樣就可以在任意數組調用contains方法

  ?

酷貓電影網[www.aikan.tv/special/kumiaodianyingwang/]
1 2 3 4 5 6 7 8 9 10 11 12 /** * 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; }

  用法:

  ?

1 2 3 4 5 // Now you can do things like: var x = Array(); if (x.contains('foo')) { // do something special }

  希望本文所述對大家的javascript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 瓦房店市| 华阴市| 西乡县| 娄底市| 天台县| 香格里拉县| 静乐县| 通许县| 远安县| 平原县| 竹山县| 启东市| 上饶市| 遂昌县| 阿尔山市| 南投市| 茌平县| 南安市| 景德镇市| 南昌县| 高密市| 新干县| 舞阳县| 赤峰市| 永和县| 克山县| 牟定县| 汾阳市| 县级市| 绥阳县| 潼南县| 小金县| 南丰县| 南安市| 中宁县| 来凤县| 昂仁县| 池州市| 昌都县| 南雄市| 共和县|