Whenever I click on an element in the array, it gets added to the new array at the end
<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 am looking to enable removal of an element from the array by clicking on it again. I attempted to use the splice method but struggling with obtaining the index of the selected item. Can you guide me on how to achieve this?