Get country code by country name javascript?

Viewed 4682

Is there a way to get the country code (Alpha-2) from a country name in JavaScript?

1 Answers

You can use this API https://restcountries.eu/

fetch("https://restcountries.eu/rest/v2/name/kenya").then(resp=>{
      return resp.json();
}).then(json=>{
      console.log(json[0].alpha2Code);
})
Related