Skip to content

arrayIndexOfMethods

Reports using .findIndex() or .findLastIndex() with simple equality checks that can be replaced with .indexOf() or .lastIndexOf().

✅ This rule is included in the ts stylistic presets.

Array.prototype.findIndex() and Array.prototype.findLastIndex() are intended for more complex predicate checks. When the callback only performs a simple strict equality check (x === value), .indexOf() or .lastIndexOf() are more readable and expressive.

This rule reports when .findIndex() or .findLastIndex() can be simplified.

declare const array: string[];
array.findIndex((item) => item === "value");
declare const array: string[];
array.findIndex((item) => "value" === item);
declare const array: string[];
array.findLastIndex((item) => item === "value");
declare const array: string[];
array.findIndex(function (item) {
return item === "value";
});

This rule is not configurable.

If you prefer the functional style of .findIndex() for consistency, or if your codebase has a large number of existing uses, you may disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.