Having trouble with Array.prototype.find()

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.

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

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

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

Thanks. Feel like an idiot now.

Common mistake :slight_smile: Don’t feel bad.