I have a flat array of objects like this:
[
{ id: 0 },
{ id: 1, group: "a" },
{ id: 2, group: "a" },
{ id: 3, group: "a/b" },
{ id: 4 },
{ id: 5, group: "a/b" },
]
the goal is to transform this array into a nested array based on the group property. The expected result would look like this:
[
{ id: 0 },
[
{ id: 1, group: "a" },
{ id: 2, group: "a" }
[
{ id: 3, group: "a/b" },
{ id: 5, group: "a/b" }
],
],
{ id: 4 },
]
Is there an easy way to accomplish that?
groupcontent and items are not ordered, you'd need to iterate and IMHO order the elements before you do the nesting.