Flatten nested arrays:
let nested = [1, [2, 3], [4, [5, 6]]]
console.log(nested.flat()) // [1, 2, 3, 4, [5, 6]]
console.log(nested.flat(2)) // [1, 2, 3, 4, 5, 6]
// flatMap combines map and flat(1)
let arr = [1, 2, 3]
let result = arr.flatMap(x => [x, x * 2])
console.log(result) // [1, 2, 2, 4, 3, 6]
flat() flattens one level by default. Pass a depth for deeper flattening.