Here is the code structure I want to share with you before explaining my requirements. It displays the input array layout along with the desired outcome:
[
{
link: "someurl",
name: "Foo",
subCats: [
{
link: "anotherurl",
name: "Bar",
subCats: [
{
link: "anotherurl",
subCats: [
{
link: "onemorekink"
name: "Prod",
}
]
}
]
},
{
link: "someurll",
name: "Fuzzy",
subCats: [
{
link: "besturiever",
name: "SomeName",
subCats: [
{
link: "onemore",
name: "Aloc",
subCats: [
{
link: "anotherlink"
name: "Final",
}
]
}
]
}
]
}
]
}
]
Now, let me describe the expected result:
{
link: "onemorekink"
name: "Prod",
},
{
link: "anotherlink"
name: "Final",
}
Hopefully, you grasp the concept. Essentially, I aim to extract the final subCats
element without any child subCats
and add it to the resulting array. I attempted using Lodash for its excellent array and object manipulation capabilities. Thank you in advance for your assistance.