How do I calculate the unique values of an object property when I have an array of objects?
let organisations = [
{
"id": 1,
"name": "nameOne",
},
{
"id": 2,
"name": "nameTwo",
},
{
"id": 3,
"name": "nameOne",
}
]
In this case, how do I calculate the number of unique organisation names. The answer here is two, because there are two unique names.
This doesn't work
var counts = this.filteredExtendedDeals.reduce(
(organisations, name) => {
counts[name] = (counts[name] || 0) + 1;
return counts;
},
{}
);
return Object.keys(counts);