# no-in-misuse

Rule `sonarjs/no-in-misuse`. "in" should not be used on arrays

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1286 by reach, #587 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-in-misuse` | yes | suggestion | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-4619/) |

## Code examples

### Incorrect: the rule reports this

```js
function func1() {
    let arr = ["a", "b", "c"];

    let expectedValue = "b";
    if (expectedValue in arr) { // Noncompliant, will be always false
        return expectedValue + " found in the array";
    } else {
        return expectedValue + " not found";
    }
}

function func2() {
    let arr = ["a", "b", "c"];

    let expectedValue = "1"; // index #1 is corresponding to the value "b"
    if (expectedValue in arr) { // Noncompliant, will be always true because the array is made of 3 elements and the #1 is always there whatever its value
        return expectedValue + " found in the array";
    } else {
        return expectedValue + " not found";
    }
}
```

### Correct: the rule accepts this

```js
function func() {
    let arr = ["a", "b", "c"];

    let expectedValue = "b";
    if (arr.includes(expectedValue)) {
        return expectedValue + " was found in the array";
    } else {
        return expectedValue + " not found";
    }
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-in-misuse": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-implicit-global](https://lintradar.dev/rules/sonarjs/no-implicit-global.md): Variables should be declared explicitly
- [sonarjs/no-incompatible-assertion-types](https://lintradar.dev/rules/sonarjs/no-incompatible-assertion-types.md): Assertions comparing incompatible types should not be made
- [sonarjs/no-ignored-return](https://lintradar.dev/rules/sonarjs/no-ignored-return.md): Return values from functions without side effects should not be ignored
- [sonarjs/no-incomplete-assertions](https://lintradar.dev/rules/sonarjs/no-incomplete-assertions.md): Assertions should be complete
- [sonarjs/no-ignored-exceptions](https://lintradar.dev/rules/sonarjs/no-ignored-exceptions.md): Exceptions should not be ignored
- [sonarjs/no-internal-api-use](https://lintradar.dev/rules/sonarjs/no-internal-api-use.md): Users should not use internal APIs

---

Web page: https://lintradar.dev/rules/sonarjs/no-in-misuse. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
