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 Parameter | Description |
|---|---|
T | The type of elements within the array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr | readonly 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]