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

190
Views
How to delete an item from my Reducer Object?

I have an object in my reducer like this :

clientData : {
1080 : [{ID : 1111,name : 'John'},{ID : 2222,name : 'Stan'},],
1090 : [{ID : 3333,name : 'Adam'},{ID : 4444,name : 'Alan'},]
}

And I want to be able to delete an item (for example Stan with 2222 ID's) The problem that is I don't have the key of my property (1080), and I don't have any idea how to achieve it. I've tried the Object.values(object1) but it convert my object to array and I lost all my architecture. Have you an idea please ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Removing from existing objects might not be good, you can use Object.entries and filter to remove id.

If you want to change existing pass data to reducer

const data = {
  1080: [
    { ID: 1111, name: "John" },
    { ID: 2222, name: "Stan" },
  ],
  1090: [
    { ID: 3333, name: "Adam" },
    { ID: 4444, name: "Alan" },
  ],
};

const remove = (id, data) => {
  const entries = Object.entries(data);
  return entries.reduce((acc, [key, value]) => {
    const newValue = value.filter((item) => item.ID !== id);
    acc[key] = newValue;
    return acc;
    // return { ...acc, [key]: newValue };
  }, {}); // for updating existing data here
};


console.log(remove(2222, data))

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!