find() & findIndex() in JavaScript

From the JavaScript Array Methods cheat sheet · Searching & Testing · verified Jul 2026

find() & findIndex()

Find first element matching condition or its index

javascript
// Find first matching element
const found = [1, 2, 3].find(x => x > 1);
// 2

// Find index of first match
const index = [1, 2, 3].findIndex(x => x > 1);
// 1

// Find in objects
const user = users.find(u => u.id === 123);
const userIndex = users.findIndex(u => u.id === 123);
🟢 Essential - Better than filter()[0] for single item
💡 find() returns element, findIndex() returns index
⚡ Stops searching after first match (efficient)
⚠️ Returns undefined/-1 if nothing found
📌 Use findLast() for searching from end (ES2023)

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet