Home / Javascript Tips Generated By ChatGPT / Using Array.flatMap for Mapping and Flattening in Javascript Apply a function to each element of the array and flatten the result. Source Code let arr = [1, 2, 3, 4]; let result = arr.flatMap(x => [x, x * 2]); console.log(result); // [1, 2, 2, 4, 3, 6, 4, 8]