// RxJS v6+import { from } from'rxjs';import { last } from'rxjs/operators';constsource=from([1,2,3,4,5]);//emit last even numberconstexampleTwo=source.pipe(last(num => num %2===0));//output: "Last to pass test: 4"constsubscribeTwo=exampleTwo.subscribe(val =>console.log(`Last to pass test: ${val}`));
// RxJS v6+import { from } from'rxjs';import { last } from'rxjs/operators';constsource=from([1,2,3,4,5]);//no values will pass given predicate, emit defaultconstexampleTwo=source.pipe(last(v => v >5,'Nothing!'));//output: 'Nothing!'constsubscribeTwo=exampleTwo.subscribe(val =>console.log(val));