I receive an array from an API which looks as follows:
results = [
{name: 'Ana', country: 'US', language: 'EN'},
{name: 'Paul', country: 'UK', language: 'EN'},
{name: 'Luis', country: 'PH', language: 'SP'},
{name: 'Tom', country: 'US', language: 'EN'}
];
From this I'd like to create an array that looks like this:
countries = [
{filter: 'country', value: 'PH'},
{filter: 'country', value: 'UK'},
{filter: 'country', value: 'US'},
];
To this end, what I tried is:
countries = Array.from([...new Set(this.results.map(item => ({categoryOfFilter: 'country', value: item.country})))]);
Because I was told to use set. This does create an array as specified above, but it contains duplicates. Like so:
countries = [
{filter: 'country', value: 'US'},
{filter: 'country', value: 'UK'},
{filter: 'country', value: 'PH'},
{filter: 'country', value: 'US'},
];
Do you guys have any idea? The truth is that I was never any good with js in the first place so I'm waaay beyond stretching here.