Function flattenDepth

  • Recursively flatten array up to depth times.

    Type Parameters

    • T

    Parameters

    • array: NestedArray<T>

      The array to flatten.

    • Optionaldepth: number

      The maximum recursion depth.

    Returns T[]

    Returns the new flattened array.

    4.4.0

    flatMap, flatMapDeep, flatMapDepth, flattenDeep

    const array = [1, [2, [3, [4]], 5]]

    flattenDepth(array, 1)
    // => [1, 2, [3, [4]], 5]

    flattenDepth(array, 2)
    // => [1, 2, 3, [4], 5]