# prefer-array-find

Rule `unicorn/prefer-array-find`. Prefer `.find(…)` and `.findLast(…)` over the first or last element from `.filter(…)`.

- Source: unicorn
- Technologies: JavaScript
- Kind: performance
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 12M weekly downloads of presets that enable it
- Trend: +40.1% last quarter
- Rank: #789 by reach, #985 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-array-find` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-array-find.md) |
| Oxlint | `unicorn/prefer-array-find` | no | no | plugin `unicorn`, category perf | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-array-find.html) |

## Code examples

### Incorrect: the rule reports this

```js
const item = array.filter(x => isUnicorn(x))[0];
```

```js
const item = array.filter(x => isUnicorn(x)).shift();
```

```js
const [item] = array.filter(x => isUnicorn(x));
```

### Correct: the rule accepts this

```js
const item = array.find(x => isUnicorn(x));
```

```js
const item = array.findLast(x => isUnicorn(x));
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-array-find": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/prefer-array-find": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-add-event-listener](https://lintradar.dev/rules/unicorn/prefer-add-event-listener.md): Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions.
- [unicorn/prefer-array-flat](https://lintradar.dev/rules/unicorn/prefer-array-flat.md): Prefer `Array#flat()` over legacy techniques to flatten arrays.
- [unicorn/no-useless-promise-resolve-reject](https://lintradar.dev/rules/unicorn/no-useless-promise-resolve-reject.md): Disallow returning/yielding `Promise.resolve/reject()` in async functions or promise callbacks
- [unicorn/prefer-blob-reading-methods](https://lintradar.dev/rules/unicorn/prefer-blob-reading-methods.md): Prefer `Blob#arrayBuffer()` over `FileReader#readAsArrayBuffer(…)` and `Blob#text()` over `FileReader#readAsText(…)`.
- [unicorn/no-useless-error-capture-stack-trace](https://lintradar.dev/rules/unicorn/no-useless-error-capture-stack-trace.md): Disallow unnecessary `Error.captureStackTrace(…)`.
- [unicorn/prefer-class-fields](https://lintradar.dev/rules/unicorn/prefer-class-fields.md): Prefer class field declarations over `this` assignments in constructors.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-array-find. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
