4

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.

Jean Pierre
  • 281
  • 8
  • 21

2 Answers2

13

You can try Intl.DisplayNames() of ECMAScript Internationalization API Intl:

var getCountryNames = new Intl.DisplayNames(['en'], {type: 'region'});
console.log(getCountryNames.of('AL'));  // "Albania"
Mamun
  • 66,969
  • 9
  • 47
  • 59
3

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

noxter
  • 186
  • 1
  • 11