# toArray

#### signature: `toArray(): OperatorFunction`

## Collects all source emissions and emits them as an array when the source completes.

[![Ultimate RxJS](https://drive.google.com/uc?export=view\&id=1qq2-q-eVe-F_-d0eSvTyqaGRjpfLDdJz)](https://ultimatecourses.com/courses/rxjs?ref=4)

### Examples

**Example 1: get values emitted by interval as an array when interval completes**

( [StackBlitz](https://stackblitz.com/edit/rxjs-toarray?file=index.ts\&devtoolsheight=100) )

```js
// RxJS v6+
import { interval } from 'rxjs';
import { toArray, take } from 'rxjs/operators';

interval(100)
  .pipe(take(10), toArray())
  .subscribe(console.log);

// output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
```

### Related Recipes

* [Breakout Game](https://chasethestar.gitbook.io/ko.learn-rxjs/rxjs/recipes/breakout-game)
* [Lockscreen](https://chasethestar.gitbook.io/ko.learn-rxjs/rxjs/recipes/lockscreen)

### Additional Resources

* [toArray](https://rxjs.dev/api/operators/toArray) 📰 - Official docs

***

> 📁 Source Code: <https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/toArray.ts>
