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

151
Views
Cómo usar filter() con push() en la misma función

Quisiera saber si habría alguna forma de usar el filtro con el push en la misma función, lo intenté aquí, pero no funcionó

aquí hay un ejemplo del código

 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')) }

En console.log el filtro funciona normalmente, pero en push(resB[i]) no funciona

la salida deseada

 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}

Pero la salida también podría venir con el estado: "A", por lo que necesito el 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 answers
Answer question

0

Debido a que el filtro devuelve una matriz, no muta el original.

Es por eso que el registro de la consola te muestra, pero no se actualiza.

Necesitas

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