Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

elementAt

Emits the single value at the specified index in a sequence of emissions from the source Observable.

Emits only the i-th value, then completes.

elementAt returns an Observable that emits the item at the specified index in the source Observable, or a default value if that index is out of range and the default argument is provided. If the default argument is not given and the index is out of range, the output Observable will emit an ArgumentOutOfRangeError error.

Example

Emit only the third click event

import { fromEvent, elementAt } from 'rxjs';

const clicks = fromEvent(document, 'click');
const result = clicks.pipe(elementAt(2));
result.subscribe(x => console.log(x));

// Results in:
// click 1 = nothing
// click 2 = nothing
// click 3 = MouseEvent object logged to console
function elementAt<T, D = T>(index: number, defaultValue?: D): OperatorFunction<T, T | D>;
§
elementAt<T, D = T>(index: number, defaultValue?: D): OperatorFunction<T, T | D>
[src]

§Type Parameters

§
D = T
[src]

§Parameters

§
index: number
[src]

Is the number i for the i-th source emission that has happened since the subscription, starting from the number 0.

§
defaultValue?: D optional
[src]

§Return Type

§

A function that returns an Observable that emits a single item, if it is found. Otherwise, it will emit the default value if given. If not, it emits an error.