---
url: /docs/guide/usage/linter/rules/typescript/prefer-for-of.md
---

### What it does

Enforces the use of a `for...of` loop instead of a `for` loop with simple iteration.

### Why is this bad?

Using a `for` loop with a simple iteration over an array can be replaced with a more concise
and readable `for...of` loop. `for...of` loops are easier to read and less error-prone, as they
eliminate the need for an index variable and manual array access.

### Examples

Examples of **incorrect** code for this rule:

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

Examples of **correct** code for this rule:

```typescript
for (const item of arr) {
  console.log(item);
}
```

## How to use

## Version

This rule was added in v0.2.16.

## References
