Javascript Array find(filter)

Description

Javascript Array find(filter)


Array.prototype.find = function(filter) {
  if(typeof filter != 'function') {
    throw new Error('First argument must be a function');
  }/*from  w  w w  .ja v a 2s.  c  o m*/
  for(var i=0; i<this.length; i++) {
    var element = this[i];
    if(filter(element, i)) {
      return element;
    }
  }
};



PreviousNext

Related