0👍
I have a function that gets there.
function shuffle(arr) {
var a = [];
for (let i = 0; i < arr.length; i++) {
if (a.some(o => o["main"] === arr[i]["Main"])) {
let idx = a.findIndex(x => {
return x['main'] == arr[i].Main;
});
let copy = arr[i].SubMenu;
a[idx].submenu.push(copy)
} else {
let copy = arr[i]["SubMenu"]
let obj = {
main: arr[i]["Main"],
submenu: [copy]
}
a.push(obj);
}
}
return a;
}
This will work if you pass in the Main array
Source:stackexchange.com