国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安岳县| 东港市| 博乐市| 宽城| 安达市| 白玉县| 乾安县| 太康县| 应用必备| 伊春市| 兴仁县| 健康| 玛曲县| 平远县| 临沧市| 纳雍县| 应城市| 法库县| 互助| 儋州市| 方正县| 嘉义市| 正阳县| 时尚| 井冈山市| 静安区| 师宗县| 呼和浩特市| 珲春市| 綦江县| 门头沟区| 静安区| 无极县| 久治县| 恭城| 武城县| 新竹县| 开阳县| 元阳县| 河津市| 峡江县|