codetrix - v1.5.0
    Preparing search index...

    Function compact

    • Removes all falsy values (false, 0, '', null, undefined, NaN) from an array.

      Type Parameters

      • T

        The type of array elements.

      Parameters

      • array: T[]

        The array to compact.

      Returns T[]

      A new array with only truthy values.

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