# iteration-fallback-style

Rule `unicorn/iteration-fallback-style`. Enforce a consistent style for optional loop sources.

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

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
for (const item of items || []) {
  use(item);
}
```

```js
for (const [key, value] of Object.entries(options.config || {})) {
  use(key, value);
}
```

```js
if (items) {
  for (const item of items) {
    use(item);
  }
}
```

### Correct: the rule accepts this

```js
if (items) {
  for (const item of items) {
    use(item);
  }
}
```

```js
if (options.config) {
  for (const [key, value] of Object.entries(options.config)) {
    use(key, value);
  }
}
```

```js
for (const item of items || []) {
  use(item);
}
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/iteration-fallback-style": "error",
    },
  },
];
```

## Related rules

- [unicorn/indent](https://lintradar.dev/rules/unicorn/indent.md): Enforce consistent indentation in JSON and CSS.
- [unicorn/key-name-casing](https://lintradar.dev/rules/unicorn/key-name-casing.md): Enforce a case style for data keys.
- [unicorn/id-match](https://lintradar.dev/rules/unicorn/id-match.md): Require identifiers to match a specified regular expression.
- [unicorn/no-array-front-mutation](https://lintradar.dev/rules/unicorn/no-array-front-mutation.md): Disallow front-of-array mutation.
- [unicorn/consistent-function-style](https://lintradar.dev/rules/unicorn/consistent-function-style.md): Enforce function syntax by role.
- [unicorn/consistent-destructuring](https://lintradar.dev/rules/unicorn/consistent-destructuring.md): Use destructured variables over properties.

---

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