I am using a computed property to filter through an array of values and pull out only a set of unique items from within the array. Originally I only needed it for one variable but I need to use it to pull two different values now and can't get it to work independently of each other when making two computed properties.
Here's my Vue HTML code:
<div v-for="item in getUniques">
<input :value="item.car" v-model="selectedCars" type="checkbox">
<label> {{item.car}}</label>
</div>
Here's the function:
data(){
return {
selectedCars: [],
prefetch: [
{car: "XC90", brand: "Volvo"},
{car: "XC60", brand: "Volvo"},
{car: "XC90", brand: "Volvo"},
{car: "X-Type", brand: "Jaguar"}
]
}
},
computed: {
getUniques(){
return this.prefetch.reduce((seed, current) => {
return Object.assign(seed, {
[current.car]: current
});
}, {});
},
}
// This works perfectly for pulling out the unique values of cars and returns... [XC90,XC60, X-Type]
But when I try to create another computed property to do the same, but only work with brands, everything breaks and I get undefined. How can I tweak this computed property so I can filter out all the other unique values in this array?
I've tried everything and can't work it out. Thanks in advance for any help!!