javascript - Tally Up Repeated Items in Array -


i have following javascript array:

var president = new array(); president[0]="thomas jefferson"; president[1]="thomas jefferson"; president[2]="thomas jefferson"; president[3]="thomas jefferson"; president[4]="thomas jefferson"; president[5]="thomas jefferson"; president[6]="thomas jefferson"; president[7]="thomas jefferson"; president[8]="thomas jefferson"; president[9]="thomas jefferson"; president[10]="thomas jefferson"; president[11]="thomas jefferson"; president[12]="thomas jefferson"; president[13]="james madison"; president[14]="james madison"; president[15]="james madison"; president[16]="james madison"; president[17]="james madison"; president[18]="james madison"; president[19]="james madison"; president[20]="abraham lincoln"; president[21]="abraham lincoln"; president[22]="abraham lincoln"; president[23]="abraham lincoln"; president[24]="abraham lincoln"; president[25]="george washington"; 

how tally repeated items output follows:

thomas jefferson: 13 james madison: 7 abraham lincoln: 5 george washington: 1 

thanks help!

i'm not javascript developer, based on this article on hash tables in js looks want following:

var h = new object(); (var p in president) {     if (h.hasitem(p)) {         h.setitem(p, h.getitem(p) + 1);     }     else {         h.setitem(p, 1);     } }  (var p in h) {     document.write(p);     document.write(":");     document.write(h.getitem(p));     document.write("<br />"); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -