I have recently started working in Javascript and kinda stuck as to how below scenario supposed to work. I have gone through several examples but not able to figure out.
const mobiles = [
{
BRAND_NAME: 'Samsung',
MODEL_NAME: 'Galaxy Note 9',
MANUFACTURE_DATE: '2021-11-02'
},
{
BRAND_NAME: 'Samsung',
MODEL_NAME: 'Galaxy S10',
MANUFACTURE_DATE: '2021-10-02'
},
{
BRAND_NAME: 'Apple',
MODEL_NAME: 'Iphone X',
MANUFACTURE_DATE: '2020-11-02'
}
];
I have to convert the above array object and group by brand's name. The output should look like below -
[{
"brandname" : 'Samsung',
"details" : [{
modelname: 'Galaxy Note 9",
manufacturedate: '2021-11-02'
},
{
modelname: 'Galaxy S10'
manufacturedate: '2021-10-02'
}]
},
{
"brandname" : 'Apple',
"details" : [{
modelname: 'IPhone X",
manufacturedate: '2020-11-02'
}]
}
]
I searched around and came across various articles where they say to use map if you want a new Array object. I am confused how to go about this and whether to use map, reduce or any other function.
Any suggestion how to go about it?