O.K. I have this code..
This code works on sorting an associative array. The only problem is if there are duplicates that need to be sorted (ex: "New Delhi", "Paris", "London", "Paris") it fails miserably. Has anyone messaed around with associative array sorting? Any way of getting this script to work with duplicates? Thanks for your time.
Code:
var capitals = new Array();
capitals("New Delhi") = "India";
capitals("Beijing") = "China";
capitals("London") = "Britain";
capitals("Paris") = "France";
var s_capitals = new Array("New Delhi", "Beijing", "London", "Paris");
s_capitals.sort();
for(i = 0; i < s_capitals.length; i++) {
document.write("<p>" + s_capitals[i] + ": " + capitals[s_capitals[i]] + "</p>");
}
This code works on sorting an associative array. The only problem is if there are duplicates that need to be sorted (ex: "New Delhi", "Paris", "London", "Paris") it fails miserably. Has anyone messaed around with associative array sorting? Any way of getting this script to work with duplicates? Thanks for your time.