• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Angular / Map – Removing duplicates from the array

Map – Removing duplicates from the array

export class SidebarComponent {
  jobs: any[] = [];
  categories: any[] = [];

  constructor(private jobsService: JobsService) {}

  ngOnInit() {
    this.jobsService.getJobs().subscribe(
      (response) => {
        this.jobs = response.data;
        // Kategóriák tömbjének lekérése és duplikációk eltávolítása
        const categories = response.data
          // Kinyerjük a kategóriákat az adatokból
          .map((job) => job.attributes.category.data.attributes.Name)
          // Egy Set segítségével eltávolítjuk a duplikációkat
          .filter(
            (category, index, array) => array.indexOf(category) === index
          );

        this.categories = categories.map((category) => ({ Name: category }));
      },
      (error) => {
        console.error('Error fetching jobs', error);
      }
    );
  }
}

Filed Under: Angular

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved