Javascript Array intersect(array)

Description

Javascript Array intersect(array)


Array.prototype.intersect = function (array) {
    array = Array.isArray(array) ? array : [];
    return this.filter(function (n) {
        return array.indexOf(n) != -1;
    });/* w w w  .j  av  a 2s . com*/
};

Javascript Array intersect(array)

Array.prototype.intersect = function(array){
  return(this.filter(function(n){ return array.include(n); }));
};

Javascript Array intersect(array)

Array.prototype.intersect = function(array) {
  return this.filter((x) => array.indexOf(x) != -1);
};



PreviousNext

Related