[
["Мясо",1,2,3,4,5,6],
["Мясо",1,8,3,4,5,6],
["Мясо",2,2,3,4,5,6],
["Мясо",2,9,3,4,5,6],
["Рыба",1,2,3,4,5,6],
["Рыба",2,1,3,4,5,6],
["Рыба",3,0,3,4,5,6],
["Рыба",3,7,3,4,5,6],
["Рыба",3,0,3,4,5,6],
]
[
{
id: "Мясо",
groups: {
1: [[2,3,4,5,6],[8,3,4,5,6]],
2: [[2,3,4,5,6],[9,3,4,5,6]]
}
},
{
id: "Рыба",
groups: {
1: [2,3,4,5,6],
2: [1,3,4,5,6],
3: [[0,3,4,5,6],[7,3,4,5,6],[0,3,4,5,6]]
}
}
]
Object.values(arr.reduce((acc, [ id, group, ...values ]) => {
const g = (acc[id] = acc[id] ?? { id, groups: {} }).groups;
(g[group] = g[group] ?? []).push(values);
return acc;
}, {}))