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'}                              ]                       };              } }); 

codepen

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

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -