I'm attempting to create a list of categories from an array of objects named places, here is what I have tried:
this.places.forEach((p) => {
p.categories.forEach((c) => {
if(!this.categories.some(c.id)) {
this.categories.push(c)
}
})
})
I am using an empty array to store the categories that are being added. Since places can share categories, I need to ensure that duplicates are not added to the array. Unfortunately, the method above does not achieve this.
I also attempted the following:
this.places.forEach((p) => {
p.categories.forEach((c) => {
if(!this.categories.includes(c)) {
this.categories.push(c)
}
})
})
This approach did not work either. Any assistance in finding a solution would be greatly appreciated.