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

175
Views
eliminar objetos de la matriz con filtros no funciona en javascript

Estoy tratando de eliminar un objeto de una matriz, pero no sé qué estoy haciendo mal.

Tengo esta matriz declarada:

 listA: [ { title: 'Food', value: 'Patato' }, { title: 'Drink', value: 'Cola' }, { title: 'Desert', value: 'Cheesecake' }, ],

Estoy tratando de eliminar el objeto donde su valor es 'Cola', lo que he intentado es esto:

 this.listA.filter(x => x.value !== 'Cola');

Y me devuelve la misma lista

Quiero devolver esto:

 listA: [ { title: 'Food', value: 'Patato' }, { title: 'Desert', value: 'Cheesecake' }, ],
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Su código debería estar filtrando bien, creo que el problema aquí es que el filter no modifica la matriz original, devuelve una nueva matriz con los resultados filtrados. Si desea que sobrescriba la matriz original, deberá decir this.listA = this.listA.filter(...)

about 4 years ago · Juan Pablo Isaza Report

0

const listA = [ { title: "Food", value: "Patato" }, { title: "Drink", value: "Cola" }, { title: "Desert", value: "Cheesecake" }, ]; const result = listA.filter((obj) => obj.value !== 'Cola');
about 4 years ago · Juan Pablo Isaza Report

0

Parece que tienes que hacer algo como

 this.listA = this.listA.filter(x => x.value !== 'Cola')

El método de filtro es inmutable, por lo tanto, la matriz original no cambia

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!