← TechnologyThe essentials of

find(): returning the first matching item

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 10:06. This is not editorial approval.

In a few sentences

In brief

find() returns the first appropriate item, not a list. In the absence of a match, the result is undefined.

Useful to know

Use find(), when you need one record from an array and the first match is enough. The method traverses the order of the indices and stops when the condition returns a true value. If no item responds, you get undefined. [1]

Let const books = [{id: 4, title: 'A'}, {id: 9, title: 'B'}];. The expression books.find(book => book.id === 9) returns the second object. When searching for id 30 the result is undefined. So check the found record before reading title from it.

The difference between element and position has practical significance. The returned object is not its index. Do not use the result as a number to access the array. If different records have the same identifier , find() does not prove uniqueness: it just returns the first one.

It is convenient to choose a product from an already stocked catalog. Validating whether the identifier is actually unique remains a separate data rule.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.prototype.find ↗