Skip to content

Latest commit

 

History

History
17 lines (10 loc) · 545 Bytes

how_do_you_flatten_multi_dimensional_arrays.md

File metadata and controls

17 lines (10 loc) · 545 Bytes

How do you flatten multi-dimensional arrays?

You can flatten multi-dimensional arrays using the flat() method in JavaScript. This method flattens an array up to a specified depth.

Example:

let arr = [1, [2, 3], [4, [5, 6]]];
let flattened = arr.flat(2);
console.log(flattened);  // Output: [1, 2, 3, 4, 5, 6]

Tags: intermediate, JavaScript, Arrays