By clicking on an array element, I add it to the end of the new array
<div class="grid">
<div class="cell" v-for="item in posts" :key="item">
<img :class="{active: item.isActive}" :src="item.url" alt width="293px" height="293px" @click="choosePost(item)" />
</div>
</div>
choosePost(item) {
item.isActive = !item.isActive
if (item.isActive == true) {
this.selectedPosts.push(item)
} else this.selectedPosts.splice(????, 1)
console.log(this.selectedPosts)
},
I want to make it so, that when I click on an element again, it will be removed from the array. I tried using the splice method but I don’t understand how can I get the index of the selected item. Please tell me how to do this?