Given is a data-structure as follows ...
const tree = {
name: "Documents",
type: "dir",
full: "/home/adityam/Documents",
children: [{
name: "file.txt",
type: "file",
full: "/home/adityam/Documents/file.txt",
}, {
name: "anotherFolder",
type: "dir",
full: "/home/adityam/Documents/anotherFolder",
children: [],
}],
};
... but object properties might change in value and vary by name (key) and count (amount of entries).
What's stable though, is the base data-structure with an object's/item's full
property (string value) and the possible presence of a children
property (array type, empty of not).
In order to later change a data-item's value one needs to first find/retrieve the former from the nested data-structure by e.g. an item's known full
property value.
In case of an item like ...
{
name: "anotherFolder",
type: "dir",
full: "/home/adityam/Documents/anotherFolder",
children: [],
}
... where one wants to change e.g. children
, the item first needs to be found/retrieved via its known full
property value of "/home/adityam/Documents/anotherFolder"
.
How would one achieve such a task?