Tweakr
    Preparing search index...

    Function flattenDeep

    • Recursively flattens an array up to the specified depth.

      Fully flattens if depth is Infinity (default).

      Type Parameters

      • T

      Parameters

      • array: any[]

        The array to flatten.

      • depth: number = Infinity

        Maximum depth to flatten. Default: Infinity.

      Returns T[]

      Flattened array up to the specified depth.

      flattenDeep([1, [2, [3, [4]]]], 2);
      // → [1, 2, 3, [4]]

      flattenDeep([1, [2, [3, [4]]]]);
      // → [1, 2, 3, 4]

      1.2.0