Creates a new array with all sub-array elements concatenated recursively.
Syntax
arr.flat(depth?)Example
Enter values below to update the example in real time.
const→nested→console→flat→const 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]