Learn RxJS
Search…
single

signature: single(a: Function): Observable

Emit single item that passes expression.

Examples

Example 1: Emit first number passing predicate
// RxJS v6+
import { from } from 'rxjs';
import { single } from 'rxjs/operators';
//emit (1,2,3,4,5)
const source = from([1, 2, 3, 4, 5]);
//emit one item that matches predicate
const example = source.pipe(single(val => val === 4));
//output: 4
const subscribe = example.subscribe(val => console.log(val));

Additional Resources

  • single 📰 - Official docs
Last modified 2yr ago
Copy link
Outline
Emit single item that passes expression.
Examples
Additional Resources