.find()
Published Jun 5, 2021Updated Jul 11, 2022
Contribute to Docs
The .find()
method returns the first element in the array that satisfies the given function.
Syntax
array.find(function);
The function
is a callback that is applied to each element as the array
is traversed. If no valid element is found, undefined
is returned.
Example
Finding the first temperature that’s over 90°:
const temperature = [72, 87, 92, 90, 85, 88, 81];const hot = temperature.find((element) => element >= 90);console.log(hot);// Output: 92
Codebyte Example
The following example finds the first person under 21 years old in the peopleInLine
array:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours