VDL Plugin SDK

flattenDeep

Import from @varavel/vdl-plugin-sdk/utils/arrays.

function flattenDeep<T>(arr): ExtractNestedArrayType<T>[];

Flattens all depths of a nested array.

Type Parameters

Type ParameterDescription
TThe type of elements within the array.

Parameters

ParameterTypeDescription
arrreadonly T[]The array to flatten.

Returns

ExtractNestedArrayType<T>[]

A new array that has been flattened.

Example

const arr = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
// Returns: [1, 2, 3, 4, 5, 6]