Skip to content

Function: flattenDeep()

ts
function flattenDeep<T>(array): DeepFlattened<T>[];

Recursively flattens a nested array into a single-level array. 递归地将嵌套数组完全展开为单层数组。

Type Parameters

Type ParameterDescription
TThe type of array items / 数组元素类型

Parameters

ParameterTypeDescription
arrayreadonly T[]The source array / 源数组

Returns

DeepFlattened<T>[]

A fully flattened array / 完全展开后的数组

Example

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

Since

1.2.0

Released under the MIT License.