Options
All
  • Public
  • Public/Protected
  • All
Menu

Module flattenDepth

Index

Functions Array

Array Functions

  • default(array: any[], depth?: number): any[]
  • Recursively flatten array up to depth times.

    since

    5.4.0

    see

    flatMap,flatMapDeep,flatMapDepth,flattenDeep

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

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

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

    Parameters

    • array: any[]

      The array to flatten.

    • depth: number = 1

      The maximum recursion depth.

    Returns any[]

    Returns the new flattened array.