0

Ok, so I'm coming back with an extra questions based on one I had yesterday. I have half the answer, but I don't have the most important part:

So given an object and a string path for example:

let obj1 = {
 part1: {
  elem1: {},
  eleme2:{},
},
 part2: {
  elem1: {
   name1: 'Marian'
   },
  eleme2:{},
  },
 part3: {
  elem1: {},
  elemm2: {},
  },
}

and a string path like:

'part2.elem1.name1'

How do I access that address not to get the value of it, but to change its value?

This works to get the value, but what I need is to change the value at that adress.

 let objValue = address
    .split('.')
    .reduce((acc, curr) => acc[curr], obj);

Now this basically creates a copy of whats there. But what I need is to have access of that location exactly so I can change it.

I want to mention that the object can be several layers deep and same for the adress.

Hope someone can help me with this.

Talmacel Marian Silviu
  • 1,596
  • 2
  • 6
  • 14

0 Answers0