通过国家名称javascript获取国家/地区代码?

问题描述

是否可以从JavaScript中的国家/地区名称获取国家/地区代码(Alpha-2)?

解决方法

您可以使用此API https://restcountries.eu/

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