@pmun/utils / flattenDepth
Function: flattenDepth()
ts
function flattenDepth(array, depth): any[];递归扁平化数组至指定深度
Parameters
array
any[]
要扁平化的数组
depth
number = 1
扁平化深度,默认为 1
Returns
any[]
扁平化后的新数组
Example
ts
flattenDepth([1, [2, [3, [4]]]], 1) // [1, 2, [3, [4]]]
flattenDepth([1, [2, [3, [4]]]], 2) // [1, 2, 3, [4]]
flattenDepth([1, [2, [3, [4]]]], 3) // [1, 2, 3, 4]