API Reference

Returns a single dimensional array from a nested array.

function flatten(arr: any[], levels = 0): any[]

// Example:

flatten([1, [2, 3, [4, 5]], 6]) //=> [1, 2, 3, 4, 5, 6]

flatten([1, [2, 3, [4, 5]], 6], 1) //=> [1, 2, 3, [4, 5], 6]

NOTE: If you pass in a number for levels, the function will only reduce that many dimensions of arrays. See the second example above.