Javascript Array contains(item)

Description

Javascript Array contains(item)


Array.prototype.contains = function(item){
   return RegExp("\\b"+item+"\\b").test(this);
};

Javascript Array contains(item)

'use strict';//w  w w . ja  va2  s . c  o  m

function get_intersection(collection_a, collection_b) {

  var result = [];
  for (var i = 0; i < collection_b.length; i++) {
    if (collection_a.contains(collection_b[i])) {
      result.push(collection_b[i]);
    }
  }
  return result;
}

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

module.exports = get_intersection;

Javascript Array contains(item)

Array.prototype.contains = function(item) {
  return this.indexOf(item) === -1 ? false : true
}

Javascript Array contains(item)

Array.prototype.contains = function(item) {
    return this.indexOf(item) > -1;
};

Javascript Array contains(item)

Array.prototype.contains = function (item) {
    for (i in this) {
        if (this[i] === item) {
            return true;
        }/*w w  w  . j a  v a  2  s. c om*/
    }
    return false;
};

Javascript Array contains(item)

Array.prototype.contains = function (item) {

  var i = 0;/*from  w ww  . ja  v  a  2s . co m*/

  for (i = 0; i < this.length; i += 1) {
    if (this[i] === item) {
      return true;
    }
  }

  return false;
};

Javascript Array contains(item)

Array.prototype.contains = function(item) {
 for ( var i = 0 ; i < this.length ; i++ ) {
  if ( this[i] == item ) 
   return true;/*from  ww  w  . j  a  va2  s . com*/
 }
 return false;
};



PreviousNext

Related