From the following code below I need to return only the objects that have meta.menu in them while preserving the structure.
So in the case below, only the object with "panel.users.view" would get removed. I've tried making a recursive function to traverse it but I can't figure out how to infinitely traverse it because there could be more objects. I don't know how many levels deep a routes object can get.
I've also looked through lodash and collect.js to see if there were functions that could be used for this but I'm unable to find a solution on my own.
Would greatly appreciate the help, many thanks!
const routes = [
{
path: "/panel",
name: "panel",
redirect: { name: "panel.dashboard" },
component: {},
children: [
{
path: "/dashboard",
name: "panel.dashboard",
component: {},
meta: {
menu: "main"
},
},
{
path: "/users",
name: "panel.users",
redirect: { name: "panel.dashboard" },
component: {},
children: [
{
path: "list",
name: "panel.users.list",
component: {},
meta: {
menu: "main"
},
},
{
path: "view/:user_id",
name: "panel.users.view",
component: {},
},
],
}
],
}
];
[]. You may want to reconsider the presence ofmeta.menuin parent routes because otherwise you have to include them retroactively if their children are main, this certainly doesn't make things easier. What did you try? Since you're new to SO, you may want to know 'write the code for me' questions that show no efforts aren't well-received.