I have the following data structure:
[
{
name: 'root',
children: [
{
name: 'page',
children: [
// and so on
]
}
]
}
]
I need a function to get the latest object given by a path. E.g. getCurrentTree('root.page')
should return
{
name: 'page',
children: [
// and so on
]
}
I hope you understand what I mean! I know I should do it recursively, but recursion is always a headache for me. Also I am not sure if should do this with find
or filter
? or even reduce
? Does anybody have a smart idea?
Cheers