I have a select and rowData[] when I click on the Add button, I add the name and the value on a table where I use the function .push for add the data into a JSON array, but I don't want to add duplicates values.
addItem () {
var equipos_torneo = {
id_torneo: this.id_torneo,
id_equipo: this.id_equipo,
nombre_equipo: nombre_team,
}
this.rowData.push(equipos_torneo)
console.log(equipos_torneo.id_equipo)
},
}
Table:
<tbody>
<tr
v-for="item in rowData"
:key="item.id_torneo"
>
<td>{{ item.id_torneo }}</td>
<td>{{ item.id_equipo }}</td>
<td>{{ item.nombre_equipo }}</td>
</tr>
</tbody>
id_torneo
? Or another, or all of them?this.rowData.findIndex(e => e.id_equipo === equipos_torneo.id_equipo)
in order to find out if an array already has an object in it with the sameid_equipo
property. If this function returns-1
, then you can push the new item.