• Recursively flatten array up to depth times.

    Parameters

    • array: any[]

      The array to flatten.

    • depth: number = 1

      The maximum recursion depth.

    Returns any[]

    Returns the new flattened array.

    5.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]