zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[RxJS] Filtering operator: filter

filter Rxjs Operator Filtering
2023-09-14 09:00:53 时间

This lesson introduces filter: an operator that allows us to let only certain events pass, while ignoring others.

var foo = Rx.Observable.interval(1000);

/*
--0--1--2--3--4--5--6--7-
 filter(x => x % 2 === 0)
--0-----2-----4-----6----
*/

var bar = foo.filter(x => x % 2 === 0);

bar.subscribe(
  function (x) { console.log('next ' + x); },
  function (err) { console.log('error ' + err); },
  function () { console.log('done'); },
);