Having the list of country ISO codes, they are available here for reference:
Is there a way to return the country name from it?
Like, having a function, getCountryName()
, which if called getCountryName('AL')
will return 'Albania' and so on.
I was doing it as saving the whole list and work on it as with a dictionary but I was wondering if there is a method without saving the whole countries into a list.
You can try Intl.DisplayNames()
of ECMAScript Internationalization API Intl
:
var getCountryNames = new Intl.DisplayNames(['en'], {type: 'region'});
console.log(getCountryNames.of('AL')); // "Albania"
Hei you could use the JSON version of what you need, here https://pkgstore.datahub.io/core/country-list/data_json/data/8c458f2d15d9f2119654b29ede6e45b8/data_json.json
then, with a forach, you loop over the file, with your ISO code, and when you find it, you ask your script to return the state name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With