How to reverse ES6 API Intl.DisplayNames() region value in JavaScript

382 Views Asked by At

I need to reverse this condtion, That means United States to US. I try to find out on Google but can't. How can I do it?

let regionNames = new Intl.DisplayNames(['en'], {type: 'region'});
console.log(regionNames.of('US'));  // "United States"

1

There are 1 best solutions below

0
lami On

This library should help

https://www.npmjs.com/package/country-code-lookup

// search by country name
lookup.byCountry('United Kingdom')