const arr4 = [1, 2, [3, [4, 5, [6, 7]]]] ; console.log(arr4.flatMap((element) => element).flat(2)) ; // expected output [1, 2, 3, 4, 5, 6, 7]