I'm attempting to organize a collection of objects into an array of arrays based on the 'group' key in the objects.
Current array:
array =
[
[{name:’a’,age:’4’,group:’15’},{name:’b’,age:’4’,group:’15’},
{name:’c’,age:’4’,group:’15’}],
[{name:’aa’,age:’6’,group:’12’},{name:’bb’,age:’6’,group:’12’}],
[{name:’d’,age:’5’,group:’15’},{name:’e’,age:’5’,group:’15’},
{name:’f’,age:’5’,group:’15’}],
[{name:’dd’,age:’7’,group:’12’},
{name:’ee’,age:’7’,group:’12’{name:’ff’,age:’7’,group:’12’}]
]
I aim to achieve an array that appears as:
newArray= [
{15:[[{name:’a’,age:’4’,group:’15’},{name:’b’,age:’4’,group:’15’},
{name:’c’,age:’4’,group:’15’}],[{name:’d’,age:’5’,group:’15’},
{name:’e’,age:’5’,group:’15’},{name:’f’,age:’5’,group:’15’}]
},
{12:[[{name:’aa’,age:’6’,group:’12’},{name:’bb’,age:’6’,group:’12’}],
[{name:’dd’,age:’7’,group:’12’},{name:’ee’,age:’7’,group:’12’},
{name:’ff’,age:’7’,group:’12’}]]
}
]
Many thanks!