# no-for-in-iterable

Rule `sonarjs/no-for-in-iterable`. "for in" should not be used with iterables

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2148 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const arr = [4, 3, 2, 1];

for (let value in arr) {  // Noncompliant
  console.log(value);  // logs 0, 1, 2, 3
}
```

### Correct: the rule accepts this

```js
const arr = [4, 3, 2, 1];

for (let value of arr) {
  console.log(value);
}
```

Examples from the ESLint documentation.

## Enable it

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

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

## Related rules

- [sonarjs/no-empty-test-file](https://lintradar.dev/rules/sonarjs/no-empty-test-file.md): Test files should contain at least one test case
- [sonarjs/no-function-declaration-in-block](https://lintradar.dev/rules/sonarjs/no-function-declaration-in-block.md): Function declarations should not be made within blocks
- [sonarjs/no-duplicate-string](https://lintradar.dev/rules/sonarjs/no-duplicate-string.md): String literals should not be duplicated
- [sonarjs/no-implicit-dependencies](https://lintradar.dev/rules/sonarjs/no-implicit-dependencies.md): Dependencies should be explicit
- [sonarjs/no-commented-code](https://lintradar.dev/rules/sonarjs/no-commented-code.md): Sections of code should not be commented out
- [sonarjs/no-inconsistent-returns](https://lintradar.dev/rules/sonarjs/no-inconsistent-returns.md): Functions should use "return" consistently

---

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