Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.
flat(depth?)
depth optional
The maximum recursion depth. The default is 1.
A new flattened array.
[1, [2, 3, [4, 5]]].flat()
[1, 2, 3, [4, 5]]
[1, [2, 3, [4, 5]]].flat(2)
[1, 2, 3, 4, 5]
[1, [2, 3, [4, 5]]].flat(Infinity)
[1, 2, 3, 4, 5]