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

177
Views
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 answers
Answer question

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 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

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 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!