Function flatten

Flattens a nested array into a single-dimensional array.

Flatten

const source = [1, [2, [3, [4, [5, 6]]]]] as const;
const result = flatten(source);
// result: [1, 2, 3, 4, 5, 6]
  • Type Parameters

    • S extends readonly unknown[]

      The type of the source array.

    Parameters

    • source: S

      The array to flatten.

    Returns Flatten<S>

    The flattened array.