unicorn/prefer-array-some Pedantic
What it does
Prefers using Array#some()
over Array#find()
, Array#findLast()
with comparing to undefined, or Array#findIndex()
, Array#findLastIndex()
and a non-zero length check on the result of Array#filter()
Why is this bad?
Using .some()
is more idiomatic and easier to read.
Example
Examples of incorrect code for this rule:
javascript
const foo = array.find(fn) ? bar : baz;
const foo = array.findLast((elem) => hasRole(elem)) !== null;
foo.findIndex(bar) < 0;
foo.findIndex((element) => element.bar === 1) !== -1;
foo.findLastIndex((element) => element.bar === 1) !== -1;
array.filter(fn).length === 0;
Examples of correct code for this rule:
javascript
const foo = array.some(fn) ? bar : baz;
foo.some((element) => element.bar === 1);
!array.some(fn);