Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda