object-traversal
object-traversal copied to clipboard
Accessing parent properties on arrays (grandparent)
Nice lib! I just have a quick question of something i was not able to do. Imagine you have at some point a node like this:
{
id: "1",
name: "Peter",
books: [
{name: "Funny book"} ,
{name: "Sad book"}
]
}
When the current value is the node {name:"funny Book"} accessing the parent gets the parent array and not the parent node. Is there a way to access the "id" property from the children?
📝It is possible to do it with the original object using getNodeByPath() but id is not there from the begining, I create it while I traverse the tree so i need a reference to the parent node that has been already extended
📝Also no way to get it from the array, because when the value is the array itself, key and parent are null