Good day developers Im wondering how I could group an array of objects of different values in specific sub-groups , where in each sub-group my contain objects with specific values according to the key queried.
My array would be something like this
{
'make': 'audi',
'model': 'r8',
'year': '2012'
}, {
'make': 'audi',
'model': 'rs5',
'year': '2013'
}, {
'make': 'ford',
'model': 'mustang',
'year': '2012'
}, {
'make': 'ford',
'model': 'fusion',
'year': '2015'
}, {
'make': 'kia',
'model': 'optima',
'year': '2012'
},
];
And i would like to gather by the key make
in a subgroup of name 2nd_class
all objects that in the key make
, had as value kia
or ford
, gathering the others in a group 1rst_class
Having as result an object like :
[
2nd_clas:[
{
'make': 'ford',
'model': 'mustang',
'year': '2012'
},
{
'make': 'ford',
'model': 'fusion',
'year': '2015'
},
{
'make': 'kia',
'model': 'optima',
'year': '2012'
},
] ,
1rst_class:[
{
'make': 'audi',
'model': 'r8',
'year': '2012'
},
{
'make': 'audi',
'model': 'rs5',
'year': '2013'
}
]
]
All the examples on the web always refer to grouping by key and one specific value ….
Any help would be amazing.Thanks in advance