---
url: /docs/guide/usage/linter/rules/unicorn/prefer-array-flat-map.md
---

### What it does

Prefers a single `.flatMap()` over `.map().flat()` or `.filter().flatMap()`.

### Why is this bad?

A single `.flatMap(…)` avoids creating an intermediate array.

### Examples

Examples of **incorrect** code for this rule:

```javascript
const bar = [1, 2, 3].map((i) => [i]).flat();
const result = values.filter((value) => value > 0).flatMap((value) => [value, value]);
```

Examples of **correct** code for this rule:

```javascript
const bar = [1, 2, 3].flatMap((i) => [i]);
const result = values.flatMap((value) => (value > 0 ? [value, value] : []));
```

## How to use

## Version

This rule was added in v0.0.14.

## References
