Skip to content
Advertisement

Find and update in nested json object

I used this code to find the required portion from the json object from sJhonny’s Question

Data Sample

JavaScript

Function to find

JavaScript

Use like so:

JavaScript

This code is to select matching piece from the source. But what I want is to update the source object with new value and retrieve the updated source object.

I want something like

JavaScript

My code

JavaScript

This works if i give obj[key] = 'qwe'; but if i change the code into obj[key] = newValue; its updated as undefined.

Why is that so?

Advertisement

Answer

You forgot to pass newValue in the nested call

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