I have been trying to group an objects of array by its value in React Js/JavaScript! can somebody help me with this? Here I have pasted my array of objects and also expected result.
const favColors = [
{
id: 1098,
color: 'red',
},
{
id: 1099,
color: 'green',
},
{
id: 1100,
color: 'red',
},
{
id: 1101,
color: 'red',
},
{
id: 1102,
color: 'green',
}
]
Expected output:
[{ red: [1098, 1100, 1101], green: [1099, 1102] }]