VDL Plugin SDK

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 ParameterDescription
TThe type of elements within the array.
UThe type of elements within the returned array from the iteratee function.

Parameters

ParameterTypeDescription
arrreadonly T[]The array to flatten.
iteratee(item, index, array) => UThe 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]