Skip to content

Documentation / @eventkit/base / elementAt

Function: elementAt()

ts
function elementAt<T, D>(index, defaultValue?): SingletonOperatorFunction<T, T | D>

Emits the single value at the specified index in the source observable, or a default value provided in the defaultValue argument and if the index is out of range. If the index is out of range and no default is given, an ArgumentOutOfRangeError is thrown.

Type Parameters

Type ParameterDefault type
T-
DT

Parameters

ParameterTypeDescription
indexnumberIs the number i for the i-th source emission that has happened since the subscription, starting from the number 0.
defaultValue?DThe default value returned for missing indices.

Returns

SingletonOperatorFunction<T, T | D>

Throws

When using elementAt(i), it throws an ArgumentOutOfRangeError if i < 0 or the observable has completed before yielding the i-th value.

Released under the MIT License.