Sometimes, we want to filter on array of RXJS Observable with JavaScript.
In this article, we’ll look at how to filter on array of RXJS Observable with JavaScript.
How to filter on array of RXJS Observable with JavaScript?
To filter on array of RXJS Observable with JavaScript, we use the filter function.
For instance, we write
import { filter } from "rxjs/operators";
const filteredEpicsObs = getEpics()
.pipe(filter((epic) => epic.id === id))
.subscribe((x) => {
//...
});
to call pipe on the observable returned by getEpics.
We call pipe with the filter returned by filter, which is called with a callback to match the values with the given id.
Then we get the filtered results from the subscribe callback.
Conclusion
To filter on array of RXJS Observable with JavaScript, we use the filter function.