I have an array of objects I'm looping over with Vue. Each object has a key value pair with the value being another array. How can I loop over each object and then loop over each array in that object to add all unique items to one array?
const objects: [
{
hungry: true,
name: "pete",
fruits: ["banana", "orange"]
},
{
hungry: false,
name: "sam",
fruits: ["grapes", "kiwi"]
},
{
hungry: true,
name: "george",
fruits: ["pear", "mango"]
}
]
This gets me close but it just adds each inner array to the outer array, not the unique items in that array ...
uniqueFruits: function() {
const fruitList = [];
this.objects.forEach((object)=>{
if (!fruitList.includes(object.fruits)) {
fruitList.push(objects.fruits);
}
});
return fruitList;
}
I know I need to loop inside again somehow to get the items in the inner array. Any help?