Consider the array below:
["cat", "dog", "cat", "rabbit", "cat", "lion"]
I am looking to transform this array into an object array that shows the frequency of each element, for example:
[
{ name: cat, count: 3 },
{ name: dog, count: 1 },
{ name: rabbit, count: 1 },
{ name: lion, count: 1 },
]
How would I go about accomplishing this task in Javascript? I typically use the Lodash library, so if there is a straightforward solution using it, feel free to suggest it.