JavaScript Array find() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
First match

What You’ll Learn

The find() method returns the first element that passes your test, or undefined if none match. It short-circuits on success. This tutorial covers callback syntax, five examples, handling no-match cases, and comparisons with filter() and findIndex().

01

Syntax

find(cb)

02

First hit

One element

03

No match

undefined

04

Stops early

Short-circuit

05

Objects OK

By property

06

ES2015

Modern support

Introduction

When you need one item from a list—the first user with an admin role, the first product in stock, the first score above 90—find() is the direct tool. It walks the array until your callback returns true, then returns that element immediately.

If you need all matches, use filter(). If you need the index instead of the value, use findIndex().

Understanding the find() Method

array.find(callback) invokes your callback for each element in order. The first time the callback returns a truthy value, find() returns that element and stops. If every callback is falsy, the result is undefined.

Unlike indexOf, which compares with strict equality (===), find() lets you write any custom test function—ideal for objects and complex conditions.

💡
Beginner Tip

A stored undefined value in the array can be a valid match. Distinguish “not found” from “found undefined” with findIndex() or an optional wrapper if that edge case matters in your app.

📝 Syntax

General form of Array.prototype.find:

JavaScript
array.find(callback(element, index, array), thisArg)

Parameters

  • callback — predicate tested on each element; first truthy match wins.
  • element — current array item.
  • index — optional; position of the element.
  • array — optional; the array being searched.
  • thisArg — optional; value to use as this inside the callback.

Return value

  • The first element for which the callback is truthy.
  • undefined if no element passes the test.
  • Original array unchanged.

Common patterns

  • arr.find(n => n > 20) — first number above 20.
  • users.find(u => u.id === id) — lookup by primary key.
  • arr.find(x => x?.active) — first active record.
  • arr.find(Boolean) — first truthy value.

⚡ Quick Reference

GoalCode
First matcharr.find(callback)
First > 20arr.find(n => n > 20)
No matchundefined
Stops early?Yes
Return typeElement or undefined

📋 find() vs filter() vs findIndex() vs indexOf

Pick the method that returns the shape you actually need: value, array, index, or simple equality.

find
first value

Element or undefined

filter
all matches

New array

findIndex
first index

Number or -1

indexOf
=== search

Primitives only

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Search primitives with a custom predicate.

Example 1 — Return the First Number Greater Than 20

find() stops at the first passing element—here that is 25, not 40.

JavaScript
const numbers = [10, 25, 5, 40, 15];

const result = numbers.find((n) => n > 20);

console.log(result);
// 25
Try It Yourself

How It Works

Index 0 (10) fails. Index 1 (25) passes, so find() returns 25 immediately without checking 40.

Example 2 — Handle undefined When Nothing Matches

Always guard against a missing result before using it.

JavaScript
const numbers = [10, 25, 5, 40, 15];

const result = numbers.find((n) => n > 50);

if (result !== undefined) {
  console.log(result);
} else {
  console.log("No element found.");
}
// No element found.
Try It Yourself

How It Works

No number exceeds 50, so find() returns undefined. Optional chaining (result?.toFixed) is another safe pattern.

📈 Practical Patterns

Exact lookup and object searches.

Example 3 — Find an Exact Value

Locate a specific number with strict equality.

JavaScript
const numbers = [10, 25, 5, 40, 15];
const target = 5;

const found = numbers.find((n) => n === target);

console.log(found);
// 5
Try It Yourself

How It Works

For simple primitive lookup, indexOf returns an index and includes returns a boolean. Use find() when the predicate is more expressive than ===.

Example 4 — Find a User by Username

Search an array of objects by a string property.

JavaScript
const users = [
  { id: 1, username: "john_doe" },
  { id: 2, username: "jane_smith" },
  { id: 3, username: "bob_jones" }
];

const foundUser = users.find((user) => user.username === "jane_smith");

console.log(foundUser);
// { id: 2, username: "jane_smith" }
Try It Yourself

How It Works

The returned object is the same reference stored in the array. Updating foundUser also updates that slot in users.

Example 5 — Find a Product by ID

Look up a catalog item when you know its numeric identifier.

JavaScript
const products = [
  { id: 101, name: "Laptop", price: 1200 },
  { id: 102, name: "Smartphone", price: 800 },
  { id: 103, name: "Tablet", price: 400 }
];

const product = products.find((p) => p.id === 102);

console.log(product);
// { id: 102, name: "Smartphone", price: 800 }
Try It Yourself

How It Works

This pattern mirrors database lookups in frontend state. For large lists, consider indexing objects in a Map keyed by id for O(1) access.

🚀 Common Use Cases

  • User lookup — find account by email, username, or id.
  • Cart & catalog — locate product by SKU or slug.
  • Config — pick the first matching rule or feature flag.
  • Validation — detect the first invalid field in a form array.
  • Navigation — resolve the active menu item from a tree.
  • Games — find the first enemy in range or alive player.

🧠 How find() Runs

1

Start at index 0

Walk the array in ascending index order.

Iterate
2

Run callback

Pass (element, index, array) to your predicate.

Test
3

Truthy?

Return that element immediately. Otherwise continue.

Match
4

End of array

If no match, return undefined.

📝 Notes

  • Returns undefined when nothing matches—not null or -1.
  • Short-circuits: elements after the first match are never tested.
  • A matching undefined element is indistinguishable from “not found” without findIndex.
  • Do not mutate the array in ways that reorder unvisited indexes during the search.
  • For last-match searches in modern JS, use findLast().
  • ES2015 method—not available in Internet Explorer without a polyfill.

Browser & Runtime Support

Array.prototype.find() was added in ES2015 (ES6). It is available in all evergreen browsers and modern Node.js versions.

Baseline · ES2015

Array.prototype.find()

Supported in Chrome 45+, Firefox 25+, Safari 7.1+, Edge 12+, and Node 4+. Not available in Internet Explorer.

97% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.find() Excellent

Bottom line: Safe for modern web apps. For IE11, polyfill or use a manual loop with an early break.

Conclusion

The find() method is the idiomatic way to grab the first array element that satisfies a condition. It is concise, stops early, and works beautifully on arrays of objects.

Remember to handle undefined, and switch to filter() or findIndex() when you need all matches or the position instead of the value.

💡 Best Practices

✅ Do

  • Check for undefined before using the result
  • Use find() when you only need the first match
  • Write clear predicates: u => u.id === targetId
  • Prefer find() over manual loops for readability
  • Use findIndex() when the index matters

❌ Don’t

  • Assume null means not found—find returns undefined
  • Use find() when you need every match (filter())
  • Mutate the array unpredictably inside the callback
  • Use find() on huge lists repeatedly without indexing
  • Forget IE11 needs a polyfill

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.find()

Your foundation for first-match array searches.

5
Core concepts
🔎 02

First only

One element.

Result
03

Short-circuit

Stops early.

Fast
04

No match

undefined

Guard
📋 05

vs filter

One vs all.

Compare

❓ Frequently Asked Questions

find() returns the first element in an array for which the callback returns a truthy value. If no element matches, it returns undefined.
No. find() only reads elements through your callback. The original array is unchanged.
It returns undefined—not null and not an empty array. Always check for undefined before using the result.
find() stops at the first match and returns that single element. filter() collects every match into a new array.
find() returns the matching element (the value). findIndex() returns the numeric index of the first match, or -1 if none.
find() is an ES2015 (ES6) feature. All modern browsers support it; Internet Explorer does not.
Did you know?

find() and findIndex() were added together in ES2015. They share the same search logic—one returns the value, the other returns where it lives. ES2023 added findLast() and findLastIndex() for tail-first searches.

Continue to findIndex()

Learn how to get the index of the first matching element instead of the value.

findIndex() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful