You can use a lookup table based on javascript multi dimensional array and using jquery
var countries = [
{"two" : "AF","three" : "AFG" },
{"two" : "AL","three" : "ALB" },
{"two" : "DZ","three" : "DZA" },
{"two" : "AS","three" : "ASM" },
{"two" : "AD","three" : "AND" },
{"two" : "AO","three" : "AGO" },
{"two" : "AI","three" : "AIA" },
{"two" : "AQ","three" : "ATA" },
{"two" : "AG","three" : "ATG" },
{"two" : "AR","three" : "ARG" },
{"two" : "AM","three" : "ARM" },
{"two" : "AW","three" : "ABW" }
];//etc
var getKeyByParameter = function(obj, parameter) {
var returnVal = "";
$.each(obj, function(key, info) {
if (info.two == parameter) {
returnVal = info.three;
return false;
};
});
return returnVal;
}
console.log(getKeyByParameter(countries, 'AG'));
Returns ATG