Here is the data structure I am working with:
[
{
name: 'root',
children: [
{
name: 'page',
children: [
// and so on
]
}
]
}
]
I am in need of a function that can retrieve the latest object based on a specified path. For example, calling getCurrentTree('root.page')
should return
{
name: 'page',
children: [
// and so on
]
}
I hope my explanation is clear! Recursion tends to be challenging for me, so any help is appreciated. Should I use find
, filter
, or maybe even reduce
? If you have any clever ideas, please share!
Thanks a lot