prefer-array-flat-map
March 27, 2026 ยท View on GitHub
๐ Prefer .flatMap(โฆ) over .map(โฆ).flat().
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
Array#flatMap performs Array#map and Array#flat in one step.
Examples
// โ
const foo = bar.map(element => unicorn(element)).flat();
// โ
const foo = bar.map(element => unicorn(element)).flat(1);
// โ
const foo = bar.flatMap(element => unicorn(element));
// โ
const foo = bar.map(element => unicorn(element)).flat(2);
// โ
const foo = bar.map(element => unicorn(element)).foo().flat();
// โ
const foo = bar.flat().map(element => unicorn(element));