I have an array of items that contains several properties. One of the properties is an array of tags. What is the best way of getting all the tags used in those items and ordered by the number of times that those tags are being used on those items? I've been trying to look to underscore js but not getting the expected results.
return _.groupBy(items, 'tags');
Example of my data:
item1
- itemName: item1
- tags(array): tag1, tag2
item2
- itemName: item2
- tags(array): tag1, tag3
so I'm trying to get something like {tag1, 2}{tag2, 1}{tag3, 1}
Update: My tag contains a ID and a name. I'm trying to group by those IDs