Function: compact()
compact<
ElementType>(iterable:IterableResolvable<undefined|null|ElementType>):IterableIterator<ElementType>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/compact.ts:18
Creates a new iterable that yields all the non-nullish values (null and undefined) from the iterable.
Type Parameters
| Type Parameter | 
|---|
| ElementType | 
Parameters
| Parameter | Type | Description | 
|---|---|---|
| iterable | IterableResolvable<undefined|null|ElementType> | An iterator that contains elements to be compacted. | 
Returns
IterableIterator<ElementType>
Example
import { compact } from '@sapphire/iterator-utilities';
const iterable = [1, null, 2, undefined, 3];
console.log([...compact(iterable)]);
// Output: [1, 2, 3]