O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filtering data

We learned about some different operators to filter data from an observable; the filter() operator is probably the most common and useful. When using this operator you must provide a function to be used as a filter for each element propagated by the observable; the return of this function will be used to decide if the data should be propagated or not, and this is what happens when the result of the function is evaluated, if the result is:

  • A truthy value: the object is propagated
  • A falsy value: the object is omitted
  • The falsy values are:
    • False
    • Null
    • Undefined
    • 0
    • NaN (not a number)
    • "" (empty string)
  • The truthy values are:
    • Any non-falsy value

So when you see the following code:

Rx.Observable   .interval(100)   .filter( 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required