[译]如何在rxjs中随时间吐出数组元素November 15, 2021 · One min read张树源前端工程师原文地址:https://newbedev.com/rxjs-emit-array-items-over-time使用RxJS 6,有三种方式可以实现:1. 使用 concatMap#import { from, of, pipe } from 'rxjs';import { concatMap, delay } from 'rxjs/operators'; const array = [1, 2, 3, 4, 5]; from(array) .pipe( concatMap(val => of(val).pipe(delay(1000))), ) .subscribe(console.log);Copy2. 使用 zip 和 interval组合#import { from, pipe, interval } from 'rxjs';import { delay, zip} from 'rxjs/operators'; const array = [1, 2, 3, 4, 5]; from(array) .pipe( zip(interval(1000), (a, b) => a), ) .subscribe(console.log);Copy将 interval 作为Observable源#import { interval, pipe } from 'rxjs';import { map, take } from 'rxjs/operators'; const array = [1, 2, 3, 4, 5]; interval(1000) .pipe( take(array.length), map(i => array[i]) ) .subscribe(console.log);Copy