Javascript Array contains(value)

Description

Javascript Array contains(value)


"use strict";/*from  w ww .  ja v  a  2 s. co m*/

Array.prototype.contains = function(value){
 var n = this.length
 for (var i = 0; i < n; i++){
  if (this[i] == value) return true
 }
 return false
}

Javascript Array contains(value)

/**// w  w  w.j  a  va  2s. c  om
 * Bool check if an Array contains a value
 * 
 *
 * @example  ['Hello, world!'].contains('world!')
 *           true
 *
 * @return   {Bool} Returns bool true/false.
 */

Array.prototype.contains = Array.prototype.contains || function (value) {
    for (var i = 0, len = this.length; i < len; i++) {
      if (this[i] === value) {
        return true;
      }
    }
    return false;
}



PreviousNext

Related