Take an imaginary array of sold items where we oddly enough only are interested in the item title and value:
let items = [
{ title: "Trumping the Horns", value: 5.95 },
{ title: "Rocking about", value: 20.00 },
{ title: "Trumping the Horns", value: 5.95 }
]
I know I can get an array with the unique values rather easily:
const uniqueSales = [...new Set(items.map(item => item.title))];
But lets for instance say I want to know how many of each item I have sold, or the accumulated value of them? So:
[
{ title: "Trumping the Horns", amount: 2 },
{ title: "Rocking about", amount: 1 }
]
Is it possible to map those as well, without having to do some crazy sorting and iterating over that array? Preferebly in a one-liner. The main reason for not doing it server side is that I have a fair amount of different manipulations of the same data, and it seems most correct to just send it once and let the client handle the manipulations and presentations of the data.