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:

The 6 New Rules of Communicating

The era of teleprompters and talking points has come to an end ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­...

Contact Form

Name

Email *

Message *