flatmap < Array < JavaScript
The flatMap() method of an array returns a new array formed by applying a given callback function to each no of the array, and then flattening the result by one level. It is identical to a map() followed by a flat() of depth 1.
const numbers = [1, 2, 1];
const result = numbers.flatMap((num) => (num === 2 ? [2, 2] : 1));
console.log(result);
// [1, 2, 2, 1]