Can i convert setTimeout method to observable.timer?
This should work:
let Array = [1,2,3,4,5,6]
rxjs.interval(2000)
.pipe(
rxjs.operators.take(Array.length),
rxjs.operators.map(i => Array[i])
).subscribe(value => console.log(value));
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.3.3/rxjs.umd.min.js"></script>
It automatically ends after Array.length
items (take
) and yields the items in subscribe (map
) instead of their index.
RxJS v5 Version:
let Array = [1,2,3,4,5,6]
Rx.Observable.interval(2000)
.take(Array.length)
.map(i => Array[i])
.subscribe(value => console.log(value));
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.12/Rx.min.js"></script>