After making an API call, my array is populated with values like this:
["9777", "9777", "2.4", "9777", "2.4", "2.4", "9777", "2.4", "2.4", "9777", "9777", "2.4", "2.4", "2.4"]
My goal is to count the occurrences of each item in the array and then sort them in descending order based on the count.
I found a solution on stackoverflow which suggests the following code:
data.forEach(function (x) {
counts[x] = (counts[x] || 0) + 1;
});
While this code works, it produces strange results that make it challenging to extract the desired values. Here is an example of the results obtained: https://i.sstatic.net/bKVwT.jpg