Filters out null and undefined values from the sequence.
null
undefined
Type of elements within the source iterable.
source
The source iterable.
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.
0
const values = compact([1, null, 0, undefined]).toArray();console.log(values); // [1, 0] Copy
const values = compact([1, null, 0, undefined]).toArray();console.log(values); // [1, 0]
Filters out
nullandundefinedvalues from the sequence.