Say I have array like this:
[ \"foo\", \"bar\", \"foo\" \"bar\", \"bar\", \"bar\", \"zoom\" ]
I want to group it so I
Yes you can reduce() your array to an object with the keys and the count, like this:
reduce()
const input = [ "foo", "bar", "foo", "bar", "bar", "bar", "zoom" ]; const result = input.reduce((total, value) => { total[value] = (total[value] || 0) + 1; return total; }, {}); console.log(result);
Hope it helps!