Javascript Array includes(element)

Description

Javascript Array includes(element)


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

function sample(array) {
  var random = array[Math.floor(Math.random()*array.length)];
  return random;/*ww  w.ja v a  2  s.  c  o m*/
}


function deleteAt(array, index) {
  array.splice(index, 1);
}

Javascript Array includes(element)

EventEmitter.prototype._maxListeners = 100;

Array.prototype.includes = function (element) {
  var doesInclude = false;
  this.forEach (function (el){
    if (element.id === el.id ){
      doesInclude = true;//from ww w .  j  av  a  2  s  .  co  m
      return;
    }
  });
  return doesInclude;
};



PreviousNext

Related