25.定制版的indexOf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let arr = [3, 2, 6, 7, 6,10];
Array.prototype.findIndex1=function(fn){
for(let i=0;i<this.length;i++){
if(fn(this[i],i))
return i;
}
}
var deal=function (currentValue, currentIndex) {
// console.log(currentValue, currentIndex, currentArray);
// if(currentValue === 6){
if(currentValue === 10){
return true;
}
}
let index = arr.findIndex1(deal);

console.log(index);//5