javascript - How to avoid duplicate values in the output of v-for loop in vuejs -
i want remove or filter out duplicate values in output of v-for loop. so, 'john' appears once instead of appearing twice in output. possible in vuejs ?
js
var app = new vue({ el: "#app", data: function () { return { searchfields: ['number', 'name'], search: '', items: [ { name: 'mary'}, { name: 'john'}, { name: 'john'}, { name: 'william'} ] }; } });
vuejs filterby provides 3 arguments filter function: value of current item, index of item , whole array. following works without temporary array:
methods: { myfilter: function (val, idx, arr) { for(var = 0; < idx; i++) { if(arr[i].name === val.name) { return false; } } return true; } }
Comments
Post a Comment