# no-array-for-each

Rule `unicorn/no-array-for-each`. Forbids the use of `Array#forEach` in favor of a for loop.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 2.1M weekly downloads of presets that enable it
- Trend: +151.7% last quarter
- Rank: #1504 by reach, #8 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| Oxlint | `unicorn/no-array-for-each` | no | no | plugin `unicorn`, category restriction | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-array-for-each.html) |
| Biome | `complexity/noForEach` | no | no | group complexity, since 1.0.0 | [docs](https://biomejs.dev/linter/rules/no-for-each/) |

## Code examples

### Incorrect: the rule reports this

```js
const foo = [1, 2, 3];
foo.forEach((element) => { /* ... */ });
```

### Correct: the rule accepts this

```js
const foo = [1, 2, 3];
for (const element of foo) { /* ... */ }

for (const [index, element] of foo.entries()) { /* ... */ }
```

Examples from the Oxlint documentation.

## Enable it

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/no-array-for-each": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "complexity": {
        "noForEach": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [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% |

## Related rules

- [unicorn/custom-error-definition](https://lintradar.dev/rules/unicorn/custom-error-definition.md): Enforce correct `Error` subclassing.
- [unicorn/prefer-import-meta-properties](https://lintradar.dev/rules/unicorn/prefer-import-meta-properties.md): Prefer `import.meta.{dirname,filename}` over legacy techniques for getting file paths.
- [unicorn/require-post-message-target-origin](https://lintradar.dev/rules/unicorn/require-post-message-target-origin.md): Enforce using the `targetOrigin` argument with `window.postMessage()`.
- [unicorn/no-invalid-file-input-accept](https://lintradar.dev/rules/unicorn/no-invalid-file-input-accept.md): Disallow invalid `accept` values on file inputs.
- [unicorn/no-empty-link-text](https://lintradar.dev/rules/unicorn/no-empty-link-text.md): Disallow empty link text in Markdown.
- [unicorn/no-javascript-url](https://lintradar.dev/rules/unicorn/no-javascript-url.md): Disallow `javascript:` URLs in Markdown.

---

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