Consider this code that is accessing the data of a javascript object.
animalData.animal[i].type
'animal' : [
{'type':'dog', 'colour':'brown'},
{'type':'dog', 'colour':'yellow'},
{'type':'cat', 'colour':'grey'},
{'type':'chicken', 'colour':'orange'},
{'type':'frog', 'colour':'green'},
{'type':'cat', 'colour':'pink'},
{'type':'dog', 'colour':'yellow'},
{'type':'cat', 'colour':'grey'},
{'type':'chicken', 'colour':'black'},
{'type':'dog', 'colour':'yellow'}
]
Using modern JS how can I transform the above into another array of objects that looks like this. eg. shows a count of each and removes the duplicates?
[
{'type':'dog', 'count':'4'},
{'type':'cat', 'count':'3'},
{'type':'chicken', 'count':'2'},
{'type':'frog', 'count':'1'},
]