I'm working with a v-autocomplete that iterates through a list of users. Once I select a user and add them to another list using a button click, I want to prevent adding the same user again by comparing their unique key. How can I implement an alert if a user has already been added?
<v-autocomplete
v-model="event.user"
:items="usersData"
label="Search for speakers"
:search-input.sync="searchUser"
return-object
item-value="id"
item-text="name"
></v-autocomplete>
Here is my method to add a speaker:
addSpeaker() {
const newSpeaker = {
id: this.event.user.uid,
name: this.event.user.name,
}
this.speakers.push(newSpeaker)
this.event.user = ''
},
removeSpeaker(id) {
this.speakers = this.speakers.filter(speaker => speaker.id !== id)
}
Is there a way to check here and avoid adding a user multiple times?