Skip to content

Filtering Operators

RxJS's filtering operators are important tools for selecting only the necessary data from a stream and not letting unnecessary data through. This greatly improves the efficiency and performance of the application.

Filtering operators are a set of RxJS operators that sort the values in a stream, allowing only those that meet certain criteria to pass through. By controlling the flow of data and processing only the values you need, you can build an efficient data processing pipeline.

List of Operators

◾ Basic Filtering Operators

OperatorDescription
filterOnly let through values that match the condition
takeGet only the specified number of first values
takeLastGet the specified number of last values
takeWhileGet values while the condition is met
skipSkip the specified number of first values
skipLastSkip the specified number of last values
skipWhileSkip values while the condition is met
skipUntilSkip values until another Observable fires
firstGet the first value, or the first value that meets a condition
lastGet the last value, or the last value that meets a condition
elementAtGet the value at a specified index
findFind the first value that meets a condition
findIndexGet the index of the first value that meets a condition
ignoreElementsIgnore all values and only pass through completions/errors

◾ Time-based Filtering Operators

OperatorDescription
debounceTimeIssue the last value if no input is received for a specified time
throttleTimePass through the first value and ignore new values for the specified time
auditTimeIssue the last value after a specified time
auditControl the period with a custom Observable and issue the last value
sampleTimeSample the latest value at specified time intervals

◾ Condition-based Filtering Operators

OperatorDescription
distinctRemove all duplicate values (output only unique values)
distinctUntilChangedRemove consecutive duplicate values
distinctUntilKeyChangedDetect only changes in specific properties

Practical Use Cases

  • Practical Use Cases presents practical examples of combining multiple filtering operators (real-time search, infinite scrolling, etc.).

Released under the CC-BY-4.0 license.