I need help removing duplicate items from an array in JavaScript, but when I try to delete one, it always deletes the last occurrence! https://i.sstatic.net/NeJRJ.jpg
let app = new Vue({
el: '#app',
data: {
items: []
},
methods: {
addItem() {
this.items.push('');
},
removeItem(index) {
this.items.splice(index, 1);
}
}
});
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3543405075071b041b0405">[email protected]</a>/dist/vue.js"></script>
<div id="app">
<ul class="list-group">
<li class="list-group-item" v-for="(item , index) in items">
<a href="#" v-on:click.prevent="removeItem(index)">remove</a>
<input name="form[]" type='file'>
</li>
</ul>
<button @click='addItem'>new item</button>
</div>
Check out my JSFiddle for more details: https://jsfiddle.net/6hvbqju2/