# prefer-direct-iteration

Rule `unicorn/prefer-direct-iteration`. Prefer direct iteration over default iterator method calls.

- 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: #972 by reach, #1227 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-direct-iteration` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-direct-iteration.md) |

## Code examples

### Incorrect: the rule reports this

```js
const map = new Map();
for (const entry of map.entries()) {}
```

```js
const array = [1, 2, 3];
const values = [...array.values()];
```

```js
const map = new Map();
const copy = new Map(map.entries());
```

### Correct: the rule accepts this

```js
const map = new Map();
for (const entry of map) {}
```

```js
const array = [1, 2, 3];
const values = [...array];
```

```js
const map = new Map();
const copy = new Map(map);
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-direct-iteration": "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% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-await](https://lintradar.dev/rules/unicorn/prefer-await.md): Prefer `await` over promise chaining.
- [unicorn/prefer-dom-node-replace-children](https://lintradar.dev/rules/unicorn/prefer-dom-node-replace-children.md): Prefer `.replaceChildren()` when replacing DOM children.
- [unicorn/prefer-array-last-methods](https://lintradar.dev/rules/unicorn/prefer-array-last-methods.md): Prefer last-oriented array methods over `Array#reverse()` or `Array#toReversed()` followed by a method.
- [unicorn/prefer-early-return](https://lintradar.dev/rules/unicorn/prefer-early-return.md): Prefer early returns over conditionals wrapping the remainder of the function body.
- [unicorn/prefer-array-from-range](https://lintradar.dev/rules/unicorn/prefer-array-from-range.md): Prefer `Array.from({length}, …)` when creating range arrays.
- [unicorn/prefer-escaped-irregular-whitespace](https://lintradar.dev/rules/unicorn/prefer-escaped-irregular-whitespace.md): Prefer escape sequences for irregular whitespace characters.

---

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