/* http://download.geonames.org/export/dump/admin1Codes.txt */ $(function() { var $body = $("body") .css({ fontFamily: "Consolas", fontSize: "12px" }); $.get("admin1Codes.txt", function(data) { var lines = data.split("\n"), countries = {}; lines.pop(); $.each(lines, function(i, v) { var split = v.split("\t"), code = split[0].split("."); if (!countries[code[0]]) { countries[code[0]] = []; } countries[code[0]].push([code[1], split[1]]) }); console.log(countries); $body.html( $.map(Ox.keys(countries), function(v) { return v + ": [
" + Ox.repeat(" ", 4) + "[" + $.map(countries[v], function(v) { return '"' + v.join('", "') + '"'; }).join("],
" + Ox.repeat(" ", 4) + "[") + "]"; }).join("
],
") + "
]" ); }); });