Version: v0.5.1 - Beta.  We welcome contributors & feedback.  THanks!

List.flat

flat(depth = 1)

Description

Convert a mult-dimensional List into a single List with values from all of its sub-Lists.

depth: how many levels of sub-Lists should be flattened.

let mdList = [1, 2, [3, 4]];
mdList.flat();
//= [1, 2, 3, 4]

let mdList = [1, 2, [3, 4, [5, 6]]];
mdList.flat();
//= [1, 2, 3, 4, [5, 6]]

let mdList = [1, 2, [3, 4, [5, 6]]];
mdList.flat(2);
//= [1, 2, 3, 4, 5, 6]

See Also