
This means it may be less efficient for sparse arrays, compared to methods that only visit assigned values. Otherwise, find returns undefined.Ĭallback is invoked for every index of the array, not just those with assigned values. If so, find immediately returns the value of that element. The find method executes the callback function once for each index of the array until the callback returns a truthy value. The value of the first element in the array that satisfies the provided testing function. thisArg Optional Object to use as this inside callback.

array Optional The array that find was called on. index Optional The index (position) of the current element in the array. Syntax arr.find( callback(element])) Parameters callback Function to execute on each value in the array, taking 3 arguments:Įlement The current element in the array. If you need to find if any element satisfies the provided testing function, use ().Again, it checks each element for equality with the value instead of using a testing function. If you need to find if a value exists in an array, use ().

(It’s similar to findIndex(), but checks each element for equality with the value instead of using a testing function.) If you need to find the index of a value, use ().

