# prefer-for-of

Rule `typescript/prefer-for-of`. Enforce the use of `for-of` loop over the standard `for` loop where possible

- Source: typescript
- Technologies: TypeScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 46.7M weekly downloads of presets that enable it
- Trend: +31.9% last quarter
- Rank: #265 by reach, #1091 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/prefer-for-of` | no | no | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/prefer-for-of) |
| Oxlint | `typescript/prefer-for-of` | no | no | plugin `typescript`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-for-of.html) |
| 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

```ts
declare const array: string[];

for (let i = 0; i < array.length; i++) {
  console.log(array[i]);
}
```

### Correct: the rule accepts this

```ts
declare const array: string[];

for (const x of array) {
  console.log(x);
}

for (let i = 0; i < array.length; i++) {
  // i is used, so for-of could not be used.
  console.log(i, array[i]);
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/prefer-for-of": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/prefer-for-of": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useForOf": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [typescript-eslint stylistic](https://lintradar.dev/presets/typescript-eslint-stylistic.md) | ESLint | `@typescript-eslint/eslint-plugin` | 17 | 175.9M | +29.5% |
| [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% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [typescript/no-inferrable-types](https://lintradar.dev/rules/typescript/no-inferrable-types.md): Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean
- [typescript/class-literal-property-style](https://lintradar.dev/rules/typescript/class-literal-property-style.md): Enforce that literals on classes are exposed in a consistent style
- [typescript/array-type](https://lintradar.dev/rules/typescript/array-type.md): Require consistently using either `T[]` or `Array<T>` for arrays
- [typescript/consistent-type-definitions](https://lintradar.dev/rules/typescript/consistent-type-definitions.md): Enforce type definitions to consistently use either `interface` or `type`
- [typescript/no-mixed-enums](https://lintradar.dev/rules/typescript/no-mixed-enums.md): Disallow enums from having both number and string members
- [typescript/no-dynamic-delete](https://lintradar.dev/rules/typescript/no-dynamic-delete.md): Disallow using the `delete` operator on computed key expressions

---

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