Multidimensional array as pivot table

Multidimensional array as pivot table

I'm trying to convert this array

  1. var data = ["a","b","c","d","e","a","b","b","b","c","d","d","e","a"];

into

  1. topics  [a:3,b:4,c:2,d:3,e:2]   ( -- not sure how this notation should be)

but how?

this is my script, not working of obviously

  1. var data = ["a","b","c","d","e","a","b","b","b","c","d","d","e","a"];
  2. var topics = [,];
  3. for(i=0; i<data.length; i++){
  4.       var arrayIndex =  $.inArray(data[i], topics);
                    if(arrayIndex == -1) // return -1 if it is not in the list
                    {
                        topics.push([data[i],1]); // add it
                    }           
                    else
                    {
                        topics[arrayIndex][1] = topics[arrayIndex][1] +1; // add 1 to existing topic
                    }

  5. }