Implement Array.find

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Implement Array.find

Approach

Iterate through the array and test each element with the callback predicate. Return the first element for which the callback returns truthy, short-circuiting the loop. If no element matches, return undefined.

Complexity Analysis

Time
O(n)
Space
O(1)

Pattern

Array Polyfill

Why It Works

Find uses early return to stop iteration as soon as a match is found, making it more efficient than filter when only the first match is needed. Returning undefined for no match distinguishes it from returning a falsy found value.

Updated Feb 2026