Skip to content

prefer-array-some should also check for misuse of Array.findIndex() #1870

@KurtPreston

Description

@KurtPreston

Description

prefer-array-some checks for situations in which Array.filter(...).length > 0 and Array.find(...) != null could be better written as Array.some(...)

It would be useful to also check for a similar suboptimal pattern: Array.findIndex(...) > -1

Example:

myArray.findIndex(someCondition) > -1

is equivalent to

myArray.some(someCondition)

Fail

[1, 2, 3].findIndex((i) => i % 2) > -1

Pass

[1, 2, 3].some((i) => i % 2)

Additional Info

No response

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions