mrhrifat
mrhrifat

Reputation: 65

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

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"

Upvotes: 1

Views: 539

Answers (1)

laurent lahmy
laurent lahmy

Reputation: 1689

This library should help

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

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

Upvotes: 0

Related Questions