Skip to content

@pmun/utils / flattenDeep

Function: flattenDeep()

ts
function flattenDeep(array): any[];

递归扁平化嵌套数组至完全扁平

Parameters

array

any[]

要扁平化的数组

Returns

any[]

完全扁平化后的新数组

Example

ts
flattenDeep([1, [2, [3, [4]]]]) // [1, 2, 3, 4]
flattenDeep([[1, 2], [3, [4, [5]]]]) // [1, 2, 3, 4, 5]
flattenDeep([1, 2, 3]) // [1, 2, 3]