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 Parameter | Default type |
|---|---|
T | - |
D | T |
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | Is the number i for the i-th source emission that has happened since the subscription, starting from the number 0. |
defaultValue? | D | The 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.