# no-unnecessary-array-flat-map

Rule `unicorn/no-unnecessary-array-flat-map`. Disallow unnecessary use of `Array#flatMap()`.

- 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: #1051 by reach, #1306 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const ids = array.flatMap(value => [value.id]);
```

```js
const ids = array.filter(value => value.active).flatMap(value => [value.id]);
```

```js
const active = array.flatMap(value => value.active ? [value] : []);
```

### Correct: the rule accepts this

```js
const ids = array.map(value => value.id);
```

```js
const ids = array.filter(value => value.active).map(value => value.id);
```

```js
const active = array.filter(value => value.active);
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-unnecessary-array-flat-map": "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% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-undeclared-class-members](https://lintradar.dev/rules/unicorn/no-undeclared-class-members.md): Require class members to be declared.
- [unicorn/no-unnecessary-boolean-comparison](https://lintradar.dev/rules/unicorn/no-unnecessary-boolean-comparison.md): Disallow unnecessary comparisons against boolean literals.
- [unicorn/no-uncalled-method](https://lintradar.dev/rules/unicorn/no-uncalled-method.md): Disallow referencing methods without calling them.
- [unicorn/no-unnecessary-parameters](https://lintradar.dev/rules/unicorn/no-unnecessary-parameters.md): Disallow parameters that receive the same value at every call.
- [unicorn/no-top-level-side-effects](https://lintradar.dev/rules/unicorn/no-top-level-side-effects.md): Disallow top-level side effects in exported modules.
- [unicorn/no-unsafe-json-serialization](https://lintradar.dev/rules/unicorn/no-unsafe-json-serialization.md): Disallow known values that JSON serialization cannot represent faithfully.

---

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