@mirei/ts-collections
    Preparing search index...

    Function compact

    • Filters out null and undefined values from the sequence.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      Returns IEnumerable<NonNullable<TElement>>

      A sequence containing only the elements that are neither null nor undefined.

      The method preserves other falsy values (such as 0 or an empty string) and defers execution until the returned sequence is iterated.

      const values = compact([1, null, 0, undefined]).toArray();
      console.log(values); // [1, 0]