Having trouble with Array.prototype.find()

Having trouble with Array.prototype.find()
0.0 0

#1
function example(arr, func) {

 func(arr[2]); //true

 return arr.find(func); //returns 3 as the first index of the array that passes the test
  
  
}

example([1, 2, 3, 4], function(n) {return n >= 3;}); // 3


How come return arr.find(func); returns 3 as the first index that passes the test when func(arr[2]); returns true and therefore arr[2] should be the first index that returns true for the given test function.


#2

The explanation is wrong. .find() returns the first element that passes the condition, not the index of the first element that passes.


#3

arr[2] is what it’s returning. arr[2]'s value is 3.


#4

Man how could I be so foolish. Thanks for the answer.


#5

Thanks. Feel like an idiot now.


#6

Common mistake :slight_smile: Don’t feel bad.