Skip to content

Instantly share code, notes, and snippets.

@remy727
Created February 11, 2024 12:54
Show Gist options
  • Save remy727/968e466a6c61bf636f54aeb91650b28e to your computer and use it in GitHub Desktop.
Save remy727/968e466a6c61bf636f54aeb91650b28e to your computer and use it in GitHub Desktop.
Get Country name from Country code using JavaScript
const regionNames = new Intl.DisplayNames(
['en'], {type: 'region'}
);
console.log(regionNames.of('US')); // ๐Ÿ‘‰๏ธ "United States"
console.log(regionNames.of('GB')); // ๐Ÿ‘‰๏ธ "United kingdom"
console.log(regionNames.of('DE')); // ๐Ÿ‘‰๏ธ "Germany"
console.log(regionNames.of('AU')); // ๐Ÿ‘‰๏ธ "Australia"
@red2n
Copy link

red2n commented Jul 1, 2024

how do i get dial code from isoAlpha2Code, isoAlpha3Code?? in typescript using built in functions

@IsraelOrtuno
Copy link

Very useful. Some engines seem to have different names for the same country code. HK resolves to Hong Kong on Chrome but Hong Kong SAR China on Node.js. I guess there could be some others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment