I have an array in the following format:
var array = [ { id: '555weibo' }, { id: '578weibo' }, { id: '111facebook' }, { id: '123facebook' }, { id: '145facebookpage' }, { id: '145facebookpage' }, { id: '766facebook' }, { id: '242facebook' }, { id: '432twitter' }, { id: '432exing' } ];
I need to find the number of occurrences of facebook , twitter , xing and weibo inside this array. eg:
{ weibo: 2, facebook: 6, twitter: 1, xing: 1 }
I was looking for a solution, but nothing works.
The following code does not give the expected result. Your help is greatly appreciated. Thanks.
var filtered = _.map(diff, function(value, key) { return { id: key, count:value }; });
source share