Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to edit an item from my Reducer Objec based only with the ID?

I have a 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 edit the 444 Id’s element like this :

{ID : 4444,name : 'New Value'}

So the output should look like :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Have you an idea please how to achieve it ?
thank you

>Solution :

you can try it :

const clientData = {
  1080 : [{ID : 1111,name : 'John'},{ID : 2222,name : 'Stan'},],
  1090 : [{ID : 3333,name : 'Adam'},{ID : 4444,name : 'Alan'},]
}
Object.values(clientData).forEach(ele => {
  let a = ele.find(el => el.ID === 4444)
  if (a) a.name = 'new value'
})
console.log(clientData)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading