Array Find
Predict Output Easy
Question
What does this code print?
Code
let r = [1,2,3].find(x => x > 1);
console.log(r);
Hint
find returns the first matching element.
Explanation
find returns the first element that satisfies the callback. 1 > 1 is false, 2 > 1 is true, so it returns 2 (and stops). Unlike filter which returns all matches as an array, find returns a single value or undefined.
Related Resources
Related Lessons
- Arrays
Learn JS arrays.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.