Array.prototype.flat
to flatten nested arrays.The flat method returns a new array with the subarrays of the original array concatenated into it. It takes an optional depth parameter, which specifies how deeply nested arrays should be flattened. The default value of depth is 1.
depth
> const foo = [1, [2, 3], [4, 5], [[6]]];
> console.log(foo.flat());
[ 1, 2, 3, 4, 5, [ 6 ] ]
depth
> console.log(foo.flat(2));
[ 1, 2, 3, 4, 5, 6 ]