Optimise JavaScript loop
Use braces { in all your if blocks. It makes it easier to read.

if (byletter[firstletter]){
    byletter[firstletter]++;
}else{
    byletter[firstletter]=1;
}


You have for loops like : countries.forEach(function(c){ which are also hard to read. I'd only use this if you have a function you want to apply. 

for(var countryindex = 0; countryindex &lt; countries.length; countryindex++)
{
    var c = countries[countryindex];
    // ...
}


Use descriptive variable names. 

if (FirstLetter != newFirstLetter)
{
    var l1 = cc.length;
    var l2 = l1 + byletter[newFirstLetter];


What is l1 &amp; l2 ? What is c or cc?