Javascript Array getFirstElementThat(test)

Description

Javascript Array getFirstElementThat(test)


//like filter or reduce but stops at first found element that passes test
Array.prototype.getFirstElementThat = function(test) {

    for(var i = 0; i < this.length; i++)
    {//from  ww w .j a  va  2  s. c o m
        if (test(this[i])){
   return this[i];
  }
    }
 return null;
}



PreviousNext

Related