RxJS - 條件運算子 findIndex



此運算子將為你提供源 Observable 中第一個滿足謂詞函式中條件的值的索引。

語法

findIndex(predicate_func: function): Observable

引數

predicate_func predicate_func 會決定在條件滿足時第一個要選取的索引。

返回值

它將返回一個 observable,其中包含源 Observable 中第一個滿足謂詞函式中條件的值

示例

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));

輸出

0
廣告
© . All rights reserved.