RxJS - Conditional Operator findIndex



This operator will give you the index of the first value from source Observable which happens to satisfy the condition inside the predicate function.

Syntax

findIndex(predicate_func: function): Observable

Parameters

predicate_func The predicate_function will be deciding the first index to be picked when the condition satisfies.

Return value

It will return an observable with the first value from source Observable which happens to satisfy the condition inside the predicate function

Example

import { of } from 'rxjs';
import { findIndex } from 'rxjs/operators';

let list1 = of(24, 3, 4, 9, 10, 15);
let final_val = list1.pipe(findIndex(x => x % 2 === 0),);
final_val.subscribe(x => console.log(x));

Output

0
Advertisements