I want to write a function that can look up a value based on a key and replace that value with another. The key is a tree from the beginning of node JSON. Here is an example.
var myData = {
name : 'Dan',
address: {
city : 'Santa Clara',
details : {
'prevhouse' : ''
}
}
}
Function input is a key tree. For example, myData-address-details-prevhouse
When I pass this key with a new value, say Texas, the prevailing value will be changed to the new value that I am sending.
and the new JSON will be
var myData = {
name : 'Dan',
address: {
city : 'Santa Clara',
details : {
'prevhouse' : 'Texas'
}
}
}
Here is what I wrote so far
var tree = key.split("-");
now the tree variable contains ["myData", "address", "details", "prevhouse"]
I know that we can access the object using myData [tree [0]] [tree [1]] [tree [2]], but somehow we cannot get it dynamic from parsing.
, .
.