I am facing an issue where I need to ensure that the values being inserted are not repeated when performing a push operation.
Below is the snippet of code in question:
addAddress: function() {
this.insertAddresses.Address = this.address_address;
this.insertAddresses.State = this.selectedStateAddress;
this.insertAddresses.City = this.selectedCityAddress;
if(this.insertAddresses.Address !== "" && this.insertAddresses.State !== null && this.insertAddresses.City !== null) {
let copy = Object.assign({}, this.insertAddresses);
this.addresses.push(copy);
}
else
{
this.$message.error('Not enough data to add');
return;
}
},
Upon adding a new element, the output looks like this:
https://i.stack.imgur.com/qCiiM.png
Subsequently, clicking the add button duplicates the same values. I am seeking guidance on how to implement validation to prevent duplicate entries. What would be the appropriate approach for achieving this?