I am new to VueJS and am having an issue getting distinct values out of an array. I have a data array with multiple columns. I'm attempting to get distinct values out to use them for checkboxes. The issue I'm running into is I can't seem to get both columns while still keeping the distinct ones. Any advice would be greatly appreciated.
Incoming data example:
const array = [{
'name': 'Alpha',
'id': 1,
'note': 'asdfasdf'
},
{
'name': 'Beta',
'id': 2,
'note': 'asdfasdf'
},
{
'name': 'Alpha',
'id': 1,
'note': 'asdfasdf'
}
]
What I'd like to be the output of the function:
const array = [{
'name': 'Alpha',
'id': 1
},
{
'name': 'Beta',
'id': 2
}
]
How I would like to use the new array:
<v-checkbox
v-for="(x,i) in array"
:label="x.name"
:value="x.id"
></v-checkbox>
I have tried the code below and I do get distinct values, but only one column.
[...new Set(this.array.map((x) => x.id))]
And when I try this I get both columns I want, but with duplicates.
[...new Set(this.array.map((x) => { return { name: x.name, id: x.id }}))]