Javascript Array containsObject(obj)

Description

Javascript Array containsObject(obj)


Array.prototype.containsObject = function(obj){
    var i;/*from   ww  w  .jav  a 2 s .  c o m*/
    for (i = 0; i < this.length; i++) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
};

Javascript Array containsObject(obj)

Array.prototype.containsObject = function (obj) {
    var contains = false;
    for (var i = 0; i < this.length; i++) {
        if (this[i] == obj) {
            contains = true;/* w  w w  . ja v  a 2 s  . c  o m*/
        }
    }
    return contains;
};

Javascript Array containsObject(obj)

Array.prototype.containsObject = function(obj) {
  return this.filter(item => item === obj).length !== 0;
}



PreviousNext

Related