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?
ddoesn't have a position in Z, so you can't - properties of objects in javascript doesn't have fixed positions, objects cannot be sorted for the same reason. the only way for you to interact with it is through its name, which btw you can safely assume is unique for that object, since a js object cannot have two separate properties with the same name.