A second question about my project "Avatar database". I want to collect all tags from all avatars into one array. Of course the list should not contain duplicates.
For example, I have 3 avatars with the tag "red" and in the array "allTags" - "red" is displayed only once.
Data structure
data() {
return {
avatars: [
{
name: "Butterfly Blue",
tags: ["animal", "butterfly", "blue"]
},
{
name: "Butterfly Green",
tags: ["animal", "butterfly", "green"]
},
{
name: "Deer Shining",
tags: ["animal", "deer"]
}
]
}
}
I'm trying to get those tags using a computed property:
allTags() {
var result = [];
for (var avatar in this.avatars) {
for (var tag in avatar.tags) {
if (!tag in result) {
result += tag
}
}
}
return result
}
But... The only output I can see is: [] - an empty array.
I want the computed property allTags to return an array ([]) of all tags from all avatars.
Using the example data above {{ allTags }} should be:
[ "animal", "butterfly", "blue", "green", "deer" ]