I have this array/object of JavaScript
[
{
"name": "A",
"selected_color": "Red"
},
{
"name": "B",
"selected_color": "Green"
},
{
"name": "C",
"selected_color": "Blue"
},
{
"name": "D",
"selected_color": "Red"
}
]
How can I convert it to following format?
[
{
"color": "Red",
"count": "2"
},
{
"color": "Green",
"count": "1"
},
{
"color": "Blue",
"count": "1"
}
]
I want to filter values based on 'selected_color' key, also 'count' will store how many time specific color was selected.