lodash count unique of field

    data(){
   return:{ 
data: [
   { name: 'Hello', phone_num: '1234'},
   { name: 'Hello', phone_num: '1234'},
   { name: 'Hello', phone_num: '1234'},
   { name: 'Hello', phone_num: '1234'},
   { name: 'Hello', phone_num: '1234'},
   { name: 'Hello', phone_num: '1234'},
   { name: 'Hello', phone_num: '1234'},
   
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   { name: 'Marc', phone_num: '5432'},
   
   { name: 'Sam', phone_num: '76532'},
   { name: 'Sam', phone_num: '76532'},
   { name: 'Sam', phone_num: '76532'},
   { name: 'Sam', phone_num: '76532'}
   
 ]
}
}
  },computed:{
 productVal(){ 
  return _(this.data)
    .groupBy('name')
    .map((items, name) => ({ name, count: items.length }))
    .value();
  }
 },

//[ { "name": "Hello", "count": 7 }, { "name": "Marc", "count": 8 }, { "name": "Sam", "count": 4 } ]

No comments:

I Quit AeroMedLab

Watch now (2 mins) | Today is my last day at AeroMedLab ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­...

Contact Form

Name

Email *

Message *