Javascript Array find(iteratee, thisArg)

Description

Javascript Array find(iteratee, thisArg)

Array.prototype.find = function(iteratee, thisArg) {
 if (typeof iteratee !== "function") {
  throw new TypeError(iteratee + ' is not a function')
 }
 let arr = this;/*from  w w w  .  jav a  2s .  c o m*/
 let result;
 for (let i = 0, len = arr.length; i < len; i++) {
  if (iteratee.call(thisArg, arr[i], i, arr)) {
   result = arr[i];
   break;
  }
 }
 return result;
}



PreviousNext

Related