I want to count how many times the same value has occurred inside an object, and create a new object with the quantity added.
I have tried using filter
, map
and reduce
but it didn't work.
I have this data:
let arrayOfObjects = [
{name: 'Disney', type: 'inteira'},
{name: 'Bottieli', type: 'inteira'},
{name: 'Monster Truck', type: 'inteira'},
{name: 'Xuxa', type: 'desconto'},
{name: 'Pokémon', type: 'zaffari'},
]
And I want something like this output (make a new object without the repeated items based on the 'type' key value and showing the quantity of each item):
newArrayOfObjects = [
{name: 'Disney', type: 'inteira', quantity: 3},
{name: 'Xuxa', type: 'desconto', quantity: 1},
{name: 'Pokémon', type: 'zaffari', quantity: 1}
]