Javascript Array findOne(condition)

Description

Javascript Array findOne(condition)


Array.prototype.findOne = (condition) => {
  for (let i = 0; i < this.length; i += 1) {
    const item = this[i];/*w  w w. jav a  2 s .com*/

    if (condition(item)) {
      return item;
    }
  }

  return undefined;
};



PreviousNext

Related