Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
How do I filter an array getting loaded from the api using another static array in javascript or typescript?

I am trying to load the sectionRoles which only contains the one given in the array in filterData function but it doesn't return the filtered items.

How do I do this?

Simply, see the data contains a lot records but I want it to contain only the record which are given in the array.

  async getAllSectionRoles() {
        debugger;
        let data = await this.adminService.getAllSectionRoles().toPromise();
        this.sectionRoles = data;
        this.sectionRoles = data.filter(item => this.filterData(item.Id))
      }
    
      filterData(itemId) {
        let arr= [SectionRoleType.ResearchAndStudy,
                  SectionRoleType.Readings,
                  SectionRoleType.TaqareerAlBahasElmi,
                  SectionRoleType.TaqreerMoqaf,
                  SectionRoleType.WarqaSeyassie,
                  SectionRoleType.Derasat,
                  SectionRoleType.TaqareerDawreya,
                  SectionRoleType.ErhaabDowaly
                ];
    
        return arr.find(itemId);
  }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think instead of array , you can use Set here

Assuming your item.id is one of values from SectionRoleType

let arr= [SectionRoleType.ResearchAndStudy,
                  SectionRoleType.Readings,
                  SectionRoleType.TaqareerAlBahasElmi,
                  SectionRoleType.TaqreerMoqaf,
                  SectionRoleType.WarqaSeyassie,
                  SectionRoleType.Derasat,
                  SectionRoleType.TaqareerDawreya,
                  SectionRoleType.ErhaabDowaly
                ];
const filters = new Set(arr);

and then

this.sectionRoles = data.filter(item => filters.has(item.Id))
about 4 years ago · Juan Pablo Isaza Report

0

You can use Array.includes for that

const arr= [SectionRoleType.ResearchAndStudy,
                  SectionRoleType.Readings,
                  SectionRoleType.TaqareerAlBahasElmi,
                  SectionRoleType.TaqreerMoqaf,
                  SectionRoleType.WarqaSeyassie,
                  SectionRoleType.Derasat,
                  SectionRoleType.TaqareerDawreya,
                  SectionRoleType.ErhaabDowaly
                ];
this.sectionRoles = data.filter(item => arr.includes(item.Id))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!