Skip to content

filterNil

import { filterNil } from 'ngxtension/filter-nil';

Filter out undefined and null values from an Observable stream.

import { of } from 'rxjs';
import { filterNil } from 'ngxtension/filter-nil';
const source$ = of(undefined, null, 1, undefined);
const filtered$ = source$.pipe(filterNil());

Example 1: Removing Undefined and Null Values

Section titled “Example 1: Removing Undefined and Null Values”
const source$ = of(undefined, null, 1, 2, null);
const filtered$ = source$.pipe(filterNil());
// Output: 1, 2

No inputs needed for this operator.