JS Utils Kit
    Preparing search index...

    Function compact

    • Removes all falsy values from an array.

      Falsy values include: false, null, 0, "", undefined, and NaN.

      Type Parameters

      • T

      Parameters

      • array: readonly T[]

        A list of elements to compact

      Returns Exclude<T, Falsy>[]

      A new array with all falsy values removed

      compact([0, 1, false, 2, '', 3, null]);
      // [1, 2, 3]

      compact(['a', '', 'b', undefined]);
      // ['a', 'b']