RxJS - 实用运算符 toArray

累积 Observable 中的所有源值,并在源完成时将其作为数组输出。

语法

toArray():Observable

返回值

返回一个 Observable,当源完成时,它将源 Observable 中的值作为数组输出。

示例

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

let list1 = of(2, 3, 4, 5, 6);
let final_val = list1.pipe(toArray());
final_val.subscribe(x => console.log(x));

输出

[2, 3, 4, 5, 6]