RxJS elementAt() Filtering OperatorRxJS elementAt() operator is a filtering operator that emits a single value in a sequence of emissions from the source Observable after giving the specified index. In other words, we can say that the RxJS elementAt operator is used to fetch an item located at a specified index location in the sequence of items emitted by the source Observable. It emits only the i-th value, then completes. Syntax:Following is the syntax of the elementAt() operator: Or Parameter Explanation
Return valueThe RxJS elementAt() operator's return value is observable that emits a single item if it is found. Otherwise, it will emit the default value if it is given. If not, then it will emit an error. Let us see an example of elementAt() operator to understand it clearly. ExampleOutput: After executing the above example, you will see the following result as array: In the above example, you will see that 'click 1' and 'click 2' event will don't emit any result and only 'click 3' event will emit the result as output. This is because we have set click at element At value at 2 and the RxJS elementAt() operator uses a 0 based index.
Next TopicRxJS Operators
|