arrayFlatten

arrayFlatten(array array, [number depth]) → array newArray
Returns a new array containing all elements of the source array. All elements within a sub-array are extracted into the new array. The depth argument determines the maximum sub-array depth to extract. var array = [1, 2, [[3, 4], 5], [6]]; debug(arrayFlatten(array, 1)); // [1,2,[3,4],5,6]

Returns a new array containing all the elements of the source array. All the elements contained in a sub-array are extracted into the new array.

Parameters
Return
Examples
var array = [1, 2, [3, 4], 5, [6]]
debug(arrayFlatten(array)) // [1, 2, 3, 4, 5, 6]
debug(arrayFlatten([0, [1], [ [2] ], [ [ [3] ] ] ], 2)); // [0, 1, 2, [3]]
const array = [1, 2, [3, 4], 5, [6]]
Debug.log(array.flat()) // [1, 2, 3, 4, 5, 6]
Debug.log([0, [1], [ [2] ], [ [ [3] ] ] ].flat(2)) // [0, 1, 2, [3] ]
import itertools
array = [1, 2, [3, 4], 5, [6]]
# single-level flatten: chain takes iterables, so the scalars are wrapped
Debug.log(list(itertools.chain.from_iterable(x if isinstance(x, list) else [x] for x in array)))  # [1, 2, 3, 4, 5, 6]