Is there a built-in method in JavaScript to convert an array like:
const colorArray = ['red', 'green', 'green', 'blue', 'purple', 'red', 'red', 'black'];
into an object that counts the occurrences of each element, like this:
Object {
"red": 3,
"green": 2,
"blue": 1,
"purple": 1,
"black": 1
}
I attempted to create a custom solution with a function, but I am wondering if there is a native method available for this purpose. Any insights would be greatly appreciated!