Function compact

Removes all nullable values from an array.

const a = [1, null, 2, undefined, 3, 4, 5, null, 6];
const b = compact(a);
console.log(b); // [1, 2, 3, 4, 5, 6]
  • Type Parameters

    • S extends readonly unknown[]

      The type of the input array.

    Parameters

    • source: S

      The array to compact.

    Returns Compact<S>

    A new array with nullable values removed.