Skip to content

flatMapDeep

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

function flatMapDeep<T, U>(arr, iteratee): ExtractNestedArrayType<U>[];

Recursively maps each element in an array using a provided iteratee function and then deeply flattens the resulting array.

Type Parameters

Type Parameter Description
T The type of elements within the array.
U The type of elements within the returned array from the iteratee function.

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.

Returns

ExtractNestedArrayType\<U>[]

A new array that has been flattened.

Example

const result = flatMapDeep([1, 2, 3], n => [[n, n]]);
// [1, 1, 2, 2, 3, 3]