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

152
Visualizações
How to use filter() with push() in the same function

I would like to know if there would be a way to use the filter with the push in the same function, I tried here, but it didn't work

here is an example of the code

          this.storeS.getItensByCateg(paramId).subscribe((resB: any) => {
        scrollTo(0, 300);
        this.slicedItems = [];
        for (let i = 0; i <= 200; i++) {
          if (resB[i]) {
            this.slicedItems.push(resB[i]);
          }
            console.log(this.slicedItems.filter(item => item.status==='I'))
          }

In console.log the filter works normally, but in push(resB[i]) it doesn't work

the desired exit

estoque: null fotos: (6) ['8407.0', null, null, null, null, null] id: 8407 item_linkWeb: {id: 719, emp_id: 1, item_id: 8407, linkWeb_id: 693, updated_at: null, …} status: "I" tabela: {itemTabela_id: 4, item_id: 8407, vVenda: 212.9, vPromo: null, vPromoData: null}

But the output could also come with the status :"A", so I need the filter status==='I'

estoque: null fotos: (6) ['8407.0', null, null, null, null, null] id: 8407 item_linkWeb: {id: 719, emp_id: 1, item_id: 8407, linkWeb_id: 693, updated_at: null, …} status: "A" tabela: {itemTabela_id: 4, item_id: 8407, vVenda: 212.9, vPromo: null, vPromoData: null}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Because filter returns an array, not mutates the original.

That's why console log shows you, but it doesn't update.

You need

this.slicedItems = this.slicedItems.filter(item => item.status==='I')
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