I have a fairly complex nested object, for example:
A = {b : {c : { d : [{e:false},{g:true}] } } }
And through some algorithm I have found d
Now I have a clone of A, Z = clone(A)
I want to be able to modify the d in Z. How can I somehow store the position of d, so that I can go to that position in Z and modify it. If this were a list I could just store the index and modify at the same index. I could of course search the tree for d, but I cannot assume unique property names, and even if I could this would be slow
Any ideas?
While your algorithm finds
d, create a collection of properties to specify howdcan be found. In this case, it would look like soThen you can loop through the collection to traverse
Zfor the clone ofd: