Is it possible to extract numerous unique values from an array of objects using the Array.from(new Set) method?
For instance:
this.data = [
{
"_id": "5bf57b965401169dd81c2a51",
"age": 35,
"name": "Paige Zamora",
"gender": "female",
"company": "AUTOMON",
"reference_id": "12"
},
{
"_id": "5bf57b96c2c3b88adff4b972",
"age": 40,
"name": "Jennifer Carr",
"gender": "female",
"company": "SYNKGEN",
"reference_id": "11"
},
{
"_id": "5bf57b969dd839926db78767",
"age": 38,
"name": "Weaver Rosales",
"gender": "male",
"company": "ETERNIS",
"reference_id": "10"
},
{
"_id": "5bf57b968c845ea691e76c84",
"age": 31,
"name": "Myers Pickett",
"gender": "male",
"company": "ETERNIS",
"reference_id": "10"
},
{
"_id": "5bf57b96998c44eff083d3fa",
"age": 36,
"name": "Dona Nicholson",
"gender": "female",
"company": "ETERNIS",
"reference_id": "10"
}
]
I want to retrieve the unique values for: reference_id and the corresponding company, resulting in:
[{12, AUTOMON}, {11, SYNKGEN}, {10, ETERNIS}]
I had considered using this approach:
const list = Array.from(new Set(this.data.map(({reference_id}) => reference_id)));
which returns:
[12, 11, 10]
Can this method be adapted to return multiple values like the list provided above?