Removes all falsy values (false, 0, '', null, undefined, NaN) from an array.
false
0
''
null
undefined
NaN
The type of array elements.
The array to compact.
A new array with only truthy values.
compact([0, 1, false, 2, '', 3]); // [1, 2, 3] Copy
compact([0, 1, false, 2, '', 3]); // [1, 2, 3]
Removes all falsy values (
false
,0
,''
,null
,undefined
,NaN
) from an array.