Here is my array:
['California','Texas','Texas','Texas','New York','Missouri','New Mexico','California']
Is there a way in lodash to convert it to an object with a count of repeated occurrences like this:
[
{'name':'California', 'count':2},
{'name':'Texas', 'count':3},
{'name':'New York', 'count':1},
{'name':'Missouri', 'count':1},
{'name':'New Mexico', 'count':1},
]
I have tried many combinations but have not been successful. Docs: https://lodash.com/docs#countBy
countByworks, you just have to slightly modify the result after it's done{California: 2, Texas: 3}-- just a suggestioncountByproduces if you call it with no other arguments than the data in this post