I have an array of objects that represents a nested navigation list.
[
{
name: 'one',
link: 'blah/blah',
pages: [
{
name: 'one A'
link: 'blah/blah',
pages: []
},
{
name: 'one B'
link: 'blah/blah',
pages: []
},
{
name: 'one C'
link: null,
pages: [
{
name: 'one C I'
link: 'blah/blah',
pages: []
}
]
}
]
}
]
The first level of objects can have a link and pages the nested objects will either have a link or pages. I can't assume a limit to the depth of the nesting. I need an object for each state that includes its name, its link if it exists and all of its parents. My current solution does not account for deeper than 3 levels of nesting and adding support for each layer is laborious.
I also need to be able to search the resulting array of objects to get their link later on if that makes a difference to the solution.
I need a javascript solution but can also (and would like to) use the functions contained in the lodash library