I have an array of objects like this:
arrayOfObjs = [{1:"h"}, {1:"h"}, {2:"h"}, {3:"ha"}, {4:"haa"}, {4:"haa"}, {4:"haa"}]
I'd like to count the occurrence of each object, and get the result back in a sorted, iterable data structure, like this:
{
{4:"haa"}: 3,
{1:"h"}: 2,
{2:"h"}: 1,
{3:"ha"}: 1
}
The keys can even be in arrays. I tried using Lodash's countBy function on arrayOfObjs. However, this simply resulted in
{[object Object]:5}
Any libraries/functions I can use to get this job done? Something similar to Python's Counter
UPDATE
As an alternative, I tried to organize my array like this:
array = [[1,"h"], [1,"h"], [2,"h"], [3,"ha"], [4,"haa"], [4,"haa"], [4,"haa"]];
Again used Lodash's countBY function, and my result was:
{1,h: 2, 2,h: 1, 3,ha: 1, 4,haa: 3}
Which is a bit better, but I now I have to use regular expressions to split apart each key of the object, since "1, h" is a string. Not ideal :(
Ideally, I'd like my keys to be either objects, or arrays, or something of the sort.