Where this matters
Use find for one matching item, such as the first available appointment. Use filter when you need every match.
JavaScript · read-only example
console.log([2, 7, 9].find(n => n > 5));Read the full explanation
Find returns the first matching element. Seven matches before nine, so iteration stops there.
Trace the code
- The predicate is false for 2, so the search continues.
- It is true for 7, so find returns that element immediately.
- The later matching value 9 is not needed. The return value is not wrapped in an array.
Why the other predictions differ
[7,9]— That would be the result of filter, which collects every match.1— That is the index of the match; find returns the value, not its index.
7
Reading this explanation does not record mastery. A correct submitted attempt can do so, including after review.
Change one thing
Choose a condition no entry satisfies.
Predict the result, then run this self-contained snippet in your browser’s developer console. It uses only sample values and makes no network requests.
console.log([2, 7, 9].find(n => n > 10));Check the variation’s output
undefined
Explain which binding, value, or operation changed before moving to the next challenge.