compact es-toolkit
Returns a new array with falsy values removed.
Usage
compact(arr)
Use compact when you want to remove falsy values (false, null, 0, -0, 0n, '', undefined, NaN) from an array. A new array containing only truthy values is returned.
The type system automatically excludes falsy types.
Parameters
arrT[]required
The array to remove falsy values from.
Returns
A new array with falsy values removed.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.