const arr1 = [1, 2, 3, 4]
arr1.map(x => [x * 2])
// [[2], [4], [6], [8]]
flatMap(arr1, x => [x * 2])
// [2, 4, 6, 8]
// only one level is flattened
flatMap(arr1, x => [[x * 2]])
// [[2], [4], [6], [8]]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.
Use Array.flatMap if possible or polyfill globally: