- RxJS Tutorial
- RxJS - Home
- RxJS - Overview
- RxJS - Environment Setup
- RxJS - Latest Updates
- RxJS - Observables
- RxJS - Operators
- RxJS - Working with Subscription
- RxJS - Working with Subjects
- RxJS - Working with Scheduler
- RxJS - Working with RxJS & Angular
- RxJS - Working with RxJS & ReactJS
- RxJS Useful Resources
- RxJS - Quick Guide
- RxJS - Useful Resources
- RxJS - Discussion
RxJS - Filtering Operator elementAt
This operator will give a single value from the source observable based upon the index given.
Syntax
elementAt(index: number): Observable
Parameters
index − The argument passed is the index of type number, starting from 0. The value from the source observable for this index will be given back.
Return value
An observable will be returned with a value based on the index given.
Example
import { fromEvent} from 'rxjs'; import { elementAt } from 'rxjs/operators'; let btn = document.getElementById("btnclick"); let btn_clicks = fromEvent(btn, 'click'); let case1 = btn_clicks.pipe(elementAt(4)); case1.subscribe(x => console.log(x));
We have used elementAt(4), so the 5th click will be emitted as the index starts from 0.
Output
Advertisements
To Continue Learning Please Login
Login with Google