> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-array-flat-map

[Added in v0.6.5](https://github.com/web-infra-dev/rslint/releases/tag/v0.6.5)
## Configuration

| Preset                              | Configured Value |
| ----------------------------------- | ---------------- |
| ✅ unicornPlugin.configs.recommended | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-array-flat-map': 'error',
    },
  },
]);
```

## Rule Details

Prefer `Array#flatMap()` over chaining `Array#map()` and `Array#flat()` when the flat depth is omitted or exactly `1`.

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

```javascript
const foo = bar.map(element => unicorn(element)).flat();
const foo = bar.map(element => unicorn(element)).flat(1);
```

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

```javascript
const foo = bar.flatMap(element => unicorn(element));
const foo = bar.map(element => unicorn(element)).flat(2);
const foo = React.Children.map(children, fn).flat();
```

## Original Documentation

- [eslint-plugin-unicorn: prefer-array-flat-map](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v70.0.0/docs/rules/prefer-array-flat-map.md)
- [Source code](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v70.0.0/rules/prefer-array-flat-map.js)
