I need an efficient function to extract the index and the position of an argument in an array - but the array is could be complex.
This is the array:
let root_menu = {
nav_title: $rootScope.t['General administration'],
items: [
{ // overview
title: $rootScope.t['Overview'],
path: `/root/overview`,
module: "overview/menu",
icon: "fa fa-home"
}, // overview
{ // cardboards
title: $rootScope.t['Cardboards'],
path: `/root/cardboards`,
module: "cardboards/menu",
icon: "fa fa-files-o",
subs: [
{
title: $rootScope.t['Suppliers'],
path: `/root/cardboards/suppliers`,
module: "suppliers/menu",
icon: "fa fa-handshake-o"
},
{
title: $rootScope.t['Employees'],
path: `/root/cardboards/employees`,
module: "employees/menu",
icon: "fa fa-address-book-o"
},
]
}, // cardboards
{ // charts
title: $rootScope.t['Charts'],
path: `/root/charts`,
icon: "fa fa-area-chart",
module: "charts/menu",
subs: [
{
title: $rootScope.t['Activity'],
path: `/root/charts/activity`,
module: "charts/activity/menu"
},
]
}, // charts
{ // settings
title: $rootScope.t['Settings'],
path: `/root/settings`,
module: "settings/menu",
icon: "fa fa-cogs",
subs: [
{
title: $rootScope.t['Permissions'],
path: `/root/settings/permissions`,
module: "settings/permissions/menu",
icon: "fa fa-file-text-o"
}
]
} // settings
]
};
Now I have this breadcrumb array:
["/", "/root", "/root/cardboards", "/root/cardoards/employees", "/root/cardboards/employees/123"]
And I want to match each key (if any) in the breadcrumbs array to the first array, so I can have something like this:
[
{path: "/root/cardboards/", title: "the title from the first
array"},
{path: "/root/cardboards/employees", title: "the title from the .
first array"}
]
As you can see, if there is no match between the second and the first array (under path key), there should not be attachment to the new array.
How can I do this efficiently - better with ES6.