Function arrFlatten

  • Flattens the passed array recursively to a specified depth. Immutable.

    Type Parameters

    • T

      The type of the elements in the input array.

    Parameters

    • input: NestedArray<T>

      the array to flatten

    • maxDepth: number = Number.MAX_SAFE_INTEGER

      the maximum recursive flattening depth.

    Returns T[]

    The flattened array.

    Throws

    If the input is not an array.

    Example

    const nestedArray = [[1, 2], [3, [4, 5]], [6]];
    arrFlatten(nestedArray, 1);
    //=> [1, 2, 3, [4, 5], 6]

Generated using TypeDoc