Skip to content

Commit 68d5128

Browse files
waseemahmad31benlesh
authored andcommitted
docs(toArray): added description and example for toArray (#4775)
1 parent 81f913f commit 68d5128

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/internal/operators/toArray.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ function toArrayReducer<T>(arr: T[], item: T, index: number) {
99
return arr;
1010
}
1111

12+
/**
13+
* Collects all source emissions and emits them as an array when the source completes.
14+
*
15+
* <span class="informal">Get all values inside an array when the source completes</span>
16+
*
17+
* ![](toArray.png)
18+
*
19+
* `toArray` will wait until the source Observable completes before emitting
20+
* the array containing all emissions. When the source Observable errors no
21+
* array will be emitted.
22+
*
23+
* ## Example
24+
* ```ts
25+
* import { interval } from 'rxjs';
26+
* import { toArray, take } from 'rxjs/operators';
27+
*
28+
* const source = interval(1000);
29+
* const example = source.pipe(
30+
* take(10),
31+
* toArray()
32+
* );
33+
*
34+
* const subscribe = example.subscribe(val => console.log(val));
35+
*
36+
* // output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
37+
*
38+
* ```
39+
* @return An array from an observable sequence.
40+
* @method toArray
41+
* @owner Observable
42+
*/
1243
export function toArray<T>(): OperatorFunction<T, T[]> {
1344
return reduce(toArrayReducer, [] as T[]);
1445
}

0 commit comments

Comments
 (0)