[JavaScript] JavaScript判断数组是否包含指定的元素 →→→→→进入此内容的聊天室

来自 , 2020-03-31, 写在 JavaScript, 查看 105 次.
URL http://www.code666.cn/view/32e0bd14
  1. /**
  2.  * Array.prototype.[method name] allows you to define/overwrite an objects method
  3.  * needle is the item you are searching for
  4.  * this is a special variable that refers to "this" instance of an Array.
  5.  * returns true if needle is in the array, and false otherwise
  6.  */
  7. Array.prototype.contains = function ( needle ) {
  8.    for (i in this) {
  9.        if (this[i] == needle) return true;
  10.    }
  11.    return false;
  12. }
  13.  
  14.  
  15. //javascript/4168

回复 "JavaScript判断数组是否包含指定的元素"

这儿你可以回复上面这条便签

captcha