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

176
Visualizações
removing object from array with filters doesnt work in javascript

I am trying to remove an object from an array but it I dont know what I am doing wrong.

I have this array declared:

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

I am trying to remove the object where its value is 'Cola', what I have tried is this:

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

And it returns me the same list

I want to return this:

 listA: [
   { title: 'Food', value: 'Patato' },
   { title: 'Desert', value: 'Cheesecake' },
   ],
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Your code should be filtering just fine, I think the issue here is that filter does not modify the original array, it returns a new array with the filtered results. If you want it to overwrite the original array, you'll need to say this.listA = this.listA.filter(...)

about 4 years ago · Juan Pablo Isaza Relatório

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

0

Looks like you need to do something like

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

The filter method is immutable hence the original array isn't changed

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