RxJS - 過濾運算子 distinct



此運算子將提供源可觀察物件的與前一個值相比較時所有不同的值。

語法

distinct()

返回值

它返回具有不同值的可觀察物件。

示例

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

let all_nums = of(1, 6, 15, 1, 10, 6, 40, 10, 58, 20, 40);
let final_val = all_nums.pipe(distinct());
final_val.subscribe(x => console.log("The Distinct values are "+x));

輸出

distinct Operator
廣告
© . All rights reserved.