In this tutorial, we will learn about the toArray() operator of RXJS.

ToArray() Operator

The ToArray operator Collects all source emissions and emits them as an array when the source completes.

This is basically Used to transform data.

Which used before subscribe using pipe

Example -1:

import { toArray} from "rxjs/operators";
-----------------
users = [
    { name: "Jigar", skill: "Angular" },
    { name: "Jig", skill: "Node" },
    { name: "Jir", skill: "CSS" },
  ];

const source = from(this.users);

source.pipe(toArray()).subscribe((res) => {
      console.log(res);
});

Output:
[
    { name: "Jigar", skill: "Angular" },
    { name: "Jig", skill: "Node" },
    { name: "Jir", skill: "CSS" },
];

Example -2:

 const source = of("Jigar", "Jiya", "Aman");

 source3.pipe(toArray()).subscribe((res) => {
      console.log(res);
 });

OutPut:
["Jigar", "Jiya", "Aman"]

Topics covered:

Found this article helpful?

TutsCoder tutorials are free and ad-light — supported by readers like you. Buy me a coffee (or two ☕☕) as a token of appreciation and help keep Angular & Node.js content coming!

One-time. No subscription. 100% optional. 🙏 Every coffee counts!

Leave a Comment

Your email will not be published. Spam-free zone. ✌️

Available for Projects

Need Help With Your
Angular or Node.js Project?

7+ years of MEAN Stack experience. I build scalable Angular 21 apps, Node.js APIs, and SaaS products — delivered on time, every time.

7+ Years MEAN Stack Angular 21 + Nx Expert 20+ Projects Delivered Remote / Freelance