# prefer-array-index-of

Rule `unicorn/prefer-array-index-of`. Prefer `Array#{indexOf,lastIndexOf}()` over `Array#{findIndex,findLastIndex}()` when looking for the index of an item.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 40.5M weekly downloads of presets that enable it
- Trend: +81.2% last quarter
- Rank: #421 by reach, #413 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-array-index-of` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-array-index-of.md) |
| Oxlint | `unicorn/prefer-array-index-of` | no | no | plugin `unicorn`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-array-index-of.html) |
| Biome | `complexity/useIndexOf` | yes | unsafe | group complexity, since 2.0.0 | [docs](https://biomejs.dev/linter/rules/use-index-of/) |

## Code examples

### Incorrect: the rule reports this

```js
const index = foo.findIndex(x => x === 'foo');
```

```js
const index = foo.findIndex(x => 'foo' === x);
```

```js
const index = foo.findIndex(x => {
  return x === 'foo';
});
```

### Correct: the rule accepts this

```js
const index = foo.indexOf('foo');
```

```js
const index = foo.lastIndexOf('foo');
```

```js
const index = foo.findIndex(x => x == undefined);
```

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-index-of": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

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

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "complexity": {
        "useIndexOf": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [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 Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [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-array-flat-map](https://lintradar.dev/rules/unicorn/prefer-array-flat-map.md): Prefer `.flatMap(…)` over `.map(…).flat()` and `.filter(…).flatMap(…)`.
- [unicorn/prefer-bigint-literals](https://lintradar.dev/rules/unicorn/prefer-bigint-literals.md): Prefer `BigInt` literals over the constructor.
- [unicorn/no-useless-switch-case](https://lintradar.dev/rules/unicorn/no-useless-switch-case.md): Disallow useless case in switch statements.
- [unicorn/prefer-date-now](https://lintradar.dev/rules/unicorn/prefer-date-now.md): Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch.
- [unicorn/no-magic-array-flat-depth](https://lintradar.dev/rules/unicorn/no-magic-array-flat-depth.md): Disallow a magic number as the `depth` argument in `Array#flat(…).`
- [unicorn/prefer-math-min-max](https://lintradar.dev/rules/unicorn/prefer-math-min-max.md): Prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons.

---

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