Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda