flatMap
Import from @varavel/vdl-plugin-sdk/utils/arrays.
Maps each element in the array using the iteratee function and flattens the result up to the specified depth.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
T |
- | The type of elements within the array. |
U |
- | The type of elements within the returned array from the iteratee function. |
D extends number |
1 |
The depth to which the array should be flattened. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr |
readonly T[] |
The array to flatten. |
iteratee |
(item, index, array) => U |
The function that produces the new array elements. It receives the element, its index, and the array. |
depth? |
D |
The depth level specifying how deep a nested array structure should be flattened. Defaults to 1. |
Returns
FlatArray\<U[], D>[]
The new array with the mapped and flattened elements.