Use Array.prototype.flat() to flatten nested arrays into a single array
JavaScript sample
const nestedArray = [1, [2, [3, 4]]]; const flatArray = nestedArray.flat(2); console.log(flatArray); // Output: [1, 2, 3, 4]
Use Array.prototype.flat() to flatten nested arrays into a single array
JavaScript sample
const nestedArray = [1, [2, [3, 4]]]; const flatArray = nestedArray.flat(2); console.log(flatArray); // Output: [1, 2, 3, 4]