When working with an array of objects, I need to check if a newly inserted object is a duplicate or not.
this.duplicate = false;
for(let item of this.items){
if(item.id && this.item.name === item.name) {
this.$notify({
group: "notify",
text: "Duplicate value!",
type: "error"
});
this.duplicate = true;
}
}
if(!this.duplicate){
// Handle post/put request
}
This code currently only works for adding new items (post request). When updating existing items, it always flags them as duplicates.