← TechnologyThe essentials of

findIndex(): zero is a valid result

Publisher: ResumeMaker • 1 source

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

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

The method returns a position, and in the absence of a match -1.

Useful to know

findIndex() searches for the first element that fulfills a condition, and returns its index. For example, [8, 2, 5].findIndex(x => x < 4) gives 1. If no match, returns -1. [1]

Do not use if (index) as a check for an item found. Index 0 is valid but interpreted as false; -1 is interpreted as true. The index !== -1 condition expresses the correct verification. This is especially important if you are going to delete item by position after the search.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.findIndex ↗