Function flattenDeep

  • Flattens all depths of a nested array.

    Type Parameters

    • T

      The type of elements within the array.

    Parameters

    • arr: readonly T[]

      The array to flatten.

    Returns ExtractNestedArrayType<T>[]

    A new array that has been flattened.

    const arr = flattenDeep([1, [2, [3]], [4, [5, 6]]]);
    // Returns: [1, 2, 3, 4, 5, 6]