Javascript Array findIndex(iteratee, thisArg)

Description

Javascript Array findIndex(iteratee, thisArg)


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



PreviousNext

Related