Possible Duplicate:
How to count Matching values in Array of Javascript
I have array with elements as,
array_elements = [“2″,”1″,”2″,”2″,”3″,”4″,”3″,”3″,”3″,”5”];
i want to count array elements like following manner,
Answer:
2 comes –> 3 times
1 comes –> 1 times
3 comes –> 4 times
4 comes –> 1 times
5 comes –> 1 times
Note : Each value count should print only once.
You can sort the elements and loop through them:
Demo: http://jsfiddle.net/Guffa/aQsuP/