The
flatMap()
method returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level. It is identical to amap()
followed by aflat()
of depth 1 (arr.map(...args).flat()
), but slightly more efficient than calling those two methods separately.(c) MDN
🐊Putout plugin adds ability to apply flatMap()
. Check out in 🐊Putout Editor.
npm i @putout/plugin-apply-flat-map
{
"rules": {
"apply-flat-map": "on"
}
}
array
.map(getId)
.flat();
array.flatMap(getId);
Linter | Rule | Fix |
---|---|---|
🐊 Putout | apply-flat-map |
✅ |
⏣ ESLint | unicorn/prefer-flat-map |
✅ |
🏛 Rome | useFlatMap |
✅ |
MIT