I would like to know how many element of each number is in array, i. e.:
[2,2,3,6,1,1001,2] should return 2 => 3, 3 => 1, 6 = >1, 1 => 1, 1001 => 1. But when I use additional array when I set counted[2] = 3, and counted[1001] = 1 I create 1002 length array (in opposite to arrays in PHP I think…). How could I improve it? (of course I don’t know how many element there will be in my input array)
Thanks in advice.
I would like to know how many element of each number is in array,
Share
Use a Javascript object as a hashtable, so the numbers are represented as properties on that object: