# no-for-loop

Rule `unicorn/no-for-loop`. Do not use a `for` loop that can be replaced with a `for-of` loop.

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-for-loop` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-for-loop.md) |
| Biome | `style/useForOf` | no | no | group style, since 1.5.0 | [docs](https://biomejs.dev/linter/rules/use-for-of/) |

## Code examples

### Incorrect: the rule reports this

```js
for (let index = 0; index < array.length; index++) {
  const element = array[index];
  console.log(index, element);
}
```

```js
for (let index = 0; index < array.length; index++) {
  const element = array[index];
  console.log(element);
}
```

### Correct: the rule accepts this

```js
for (const [index, element] of array.entries()) {
  console.log(index, element);
}
```

```js
for (const element of array) {
  console.log(element);
}
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-for-loop": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useForOf": "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% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-duplicate-if-branches](https://lintradar.dev/rules/unicorn/no-duplicate-if-branches.md): Disallow duplicate adjacent branches in if chains.
- [unicorn/no-mismatched-map-key](https://lintradar.dev/rules/unicorn/no-mismatched-map-key.md): Disallow checking a Map key before accessing a different key.
- [unicorn/no-break-in-nested-loop](https://lintradar.dev/rules/unicorn/no-break-in-nested-loop.md): Disallow `break` and optionally `continue` in nested loops and switches inside loops.
- [unicorn/no-useless-recursion](https://lintradar.dev/rules/unicorn/no-useless-recursion.md): Disallow simple recursive function calls that can be replaced with a loop.
- [unicorn/isolated-functions](https://lintradar.dev/rules/unicorn/isolated-functions.md): Prevent usage of variables from outside the scope of isolated functions.
- [unicorn/prefer-continue](https://lintradar.dev/rules/unicorn/prefer-continue.md): Prefer early continues over conditionals wrapping the remainder of the loop body.

---

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