# prefer-object-iterable-methods

Rule `unicorn/prefer-object-iterable-methods`. Prefer the most specific `Object` iterable method.

- 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: #986 by reach, #1241 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
for (const key of Object.keys(object)) {
  foo(object[key]);
}
```

```js
Object.keys(object).map(key => foo(object[key], key));
```

```js
const doubled = Object.keys(object).map(key => object[key] * 2);
```

### Correct: the rule accepts this

```js
for (const value of Object.values(object)) {
  foo(value);
}
```

```js
Object.entries(object).map(([key, value]) => foo(value, key));
```

```js
const doubled = Object.values(object).map(value => value * 2);
```

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-object-iterable-methods": "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-object-define-properties](https://lintradar.dev/rules/unicorn/prefer-object-define-properties.md): Prefer `Object.defineProperties()` over multiple `Object.defineProperty()` calls.
- [unicorn/prefer-path2d](https://lintradar.dev/rules/unicorn/prefer-path2d.md): Prefer `Path2D` for repeatedly drawn canvas paths.
- [unicorn/prefer-minimal-ternary](https://lintradar.dev/rules/unicorn/prefer-minimal-ternary.md): Prefer moving ternaries into the minimal varying part of an expression.
- [unicorn/prefer-promise-static-methods](https://lintradar.dev/rules/unicorn/prefer-promise-static-methods.md): Prefer `Promise.resolve()` and `Promise.reject()` over trivial `new Promise()` calls.
- [unicorn/prefer-map-from-entries](https://lintradar.dev/rules/unicorn/prefer-map-from-entries.md): Prefer `new Map()` over `Object.fromEntries()` when using the result as a map.
- [unicorn/prefer-promise-with-resolvers](https://lintradar.dev/rules/unicorn/prefer-promise-with-resolvers.md): Prefer `Promise.withResolvers()` when extracting resolver functions from `new Promise()`.

---

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