- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Array find
JavaScript Arrays
JavaScript Array find
JavaScript
findreturns the first element that passes a test, orundefined.
Unlike filter, it gives you one element rather than an array.
It stops as soon as it finds a match.
Example
Example
javascript
const numbers = [1, 8, 3, 12];
console.log(numbers.find(n => n > 4));The output is 8, the first match.
find and findIndex
find returns the matching element itself.
