close

prefer-array-some

Added in v0.7.3

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-array-some': 'error',
    },
  },
]);

Rule Details

Prefer using Array#some(…) over:

.some(…) communicates the intent — "is there a match?" — more directly and can stop iterating at the first match.

Typed arrays carry the same methods and are checked too. Keyed collections (Map, Set, WeakMap, WeakSet) are not: their .find(…) / .filter(…) are unrelated APIs where the rewrite would not hold.

Examples of incorrect code for this rule:

if (array.find(element => element === "🦄")) {
	// …
}

const hasUnicorn = array.findIndex(element => element === "🦄") !== -1;

const hasUnicorn = array.filter(element => element === "🦄").length > 0;

const foo = array.find(element => element === "🦄") ? bar : baz;

Examples of correct code for this rule:

if (array.some(element => element === "🦄")) {
	// …
}

const hasUnicorn = array.some(element => element === "🦄");

// The result is used, not just as a boolean.
const unicorn = array.find(element => element === "🦄");

// The index is used.
const index = array.findIndex(element => element === "🦄");

Original Documentation