Skip to content
Advertisement

How can i access and change a value in an object with an array of keys

JavaScript

How can I access and change the object with the array of keys?

I have tried loadash.get but it can only get values not change them.

Advertisement

Answer

You need to do something like the following:

JavaScript

And then you could use it in the following way:

JavaScript

With a function like the above set you can update an object passing an array of nested keys and the new value.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement