I need to separate an array of objects by selected property, that came dynamically from server, my first step is to identify the quantity of labels that came in response, then i need to separate it into sets of object, based on the quantity of labels of the object ( using it to render a apex graphic bar on angular.)
I need to separate a array by categories, the api is returning something like this:
[
{name: 'Alex', classroom: "A", Age: 25},
{name: 'Rose', classroom: "A", Age: 24},
{name: 'Peter', classroom: "B", Age: 21},
{name: 'Alex', classroom: "C", Age: 22}
]
I need a output like this:
[
{classroom: "A", name: ["Alex, Rose"], Age: [25, 24]}
{classroom: "B", name: ["Peter"], Age: [21] },
{classroom: "C", name: ["Alex"], Age: [22] },
]
The use case is a lot complex than that, but the main idea is separate items by property.
What could i do to achieve something like that?