function getCountryName(countryCode) {
fetch("./countryCode.json")
.then((res) => {
return res.json();
})
.then((isoCountries) => {
console.log(countryCode)
console.log(isoCountries);
console.log(isoCountries.countryCode);
if (isoCountries.countryCode) {
return isoCountries.countryCode;
} else {
return countryCode;
}
});
} Output Below ->
IN (country code for india)
Object { AF: "Afghanistan", AX: "Aland Islands", AL: "Albania", DZ: "Algeria", AS: "American Samoa", AD: "Andorra", AO: "Angola", AI: "Anguilla", AQ: "Antarctica", AG: "Antigua And Barbuda", … }
undefined