Skip to content

unicorn/prefer-array-flat-map Style

🛠️ An auto-fix is available for this rule.

What it does

Prefers the use of .flatMap() when map().flat() are used together.

Why is this bad?

It is slightly more efficient to use .flatMap(…) instead of .map(…).flat().

Example

javascript
const bar = [1, 2, 3].map((i) => [i]).flat(); // ✗ fail

const bar = [1, 2, 3].flatMap((i) => [i]); // ✓ pass

References

Released under the MIT License.