I have an array of categories: this.categories
[ { "id": 6, "name": "categories.ladies_team" }, { "id": 2, "name": "categories.junior_team" }, { "id": 7, "name": "categories.master" }, { "id": 5, "name": "categories.ladies_single" }, { "id": 1, "name": "categories.junior" }, { "id": 3, "name": "categories.men_single" }, { "id": 4, "name": "categories.men_team" } ]
Now I have a new element:
const newCategory = {
id: category.id,
name: category.name
};
I would like to insert it if not present.
I tried:
if (!this.categories.includes(newCategory)) {
this.categories.push(newCategory);
}
but it is not working...
What am I doing wrong ?
some()element of the array matches the predicate indicating that it's present