Possible Duplicate: array_count_values for javascript instead
Let\'s say I have simple JavaScript array like
You can loop through each index and save it in a dictionary and increment it when every that key is found.
count = {}; for(a in array){ if(count[array[a]])count[array[a]]++; else count[array[a]]=1; }
Output will be:
Boat: 1 Car: 2 Truck: 2