# unicorn/prefer-array-index-of

> Require `.indexOf()` instead of `.findIndex()` when looking for a value

`.findIndex()` is for a test that `===` can't express. If the callback only compares the element with a value, `.indexOf(value)` does the same thing without a function. The same goes for `.findLastIndex()` and `.lastIndexOf()`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/prefer-array-index-of" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
const index = names.findIndex(name => name === "admin");
const last = names.findLastIndex(name => name === current);
```

Not reported:

{/* good */}
```js
const index = names.indexOf("admin");
const last = names.lastIndexOf(current);
```

A callback that compares a property of the element, or compares with `==`, isn't reported:

{/* good */}
```js
const index = users.findIndex(user => user.name === "admin");
const loose = ids.findIndex(id => id == "7");
```
