Languages
[Edit]
EN

JavaScript - list of ISO 3166 country codes

9 points
Created by:
christa
300

In this article, we would like to present simple JavaScript version of countries and associated codes to them described by ISO 3166.

The article contains two lists:

  1. one ossociated name per county codes ,
  2. many associated country names per country code - go to second example.

Note: the below list:

Country list object example:

// ONLINE-RUNNER:browser;

var Countries = new function() {

	// https://en.wikipedia.org/wiki/ISO_3166-1

	var list = [
		{code: 'AF', name: 'Afghanistan'},
		{code: 'AX', name: 'Ă…land Islands'},
		{code: 'AL', name: 'Albania'},
		{code: 'DZ', name: 'Algeria'},
		{code: 'AS', name: 'American Samoa'},
		{code: 'AD', name: 'Andorra'},
		{code: 'AO', name: 'Angola'},
		{code: 'AI', name: 'Anguilla'},
		{code: 'AQ', name: 'Antarctica'},
		{code: 'AG', name: 'Antigua and Barbuda'},
		{code: 'AR', name: 'Argentina'},
		{code: 'AM', name: 'Armenia'},
		{code: 'AW', name: 'Aruba'},
		{code: 'AU', name: 'Australia'},
		{code: 'AT', name: 'Austria'},
		{code: 'AZ', name: 'Azerbaijan'},
		{code: 'BS', name: 'Bahamas'},
		{code: 'BH', name: 'Bahrain'},
		{code: 'BD', name: 'Bangladesh'},
		{code: 'BB', name: 'Barbados'},
		{code: 'BY', name: 'Belarus'},
		{code: 'BE', name: 'Belgium'},
		{code: 'BZ', name: 'Belize'},
		{code: 'BJ', name: 'Benin'},
		{code: 'BM', name: 'Bermuda'},
		{code: 'BT', name: 'Bhutan'},
		{code: 'BO', name: 'Bolivia (Plurinational State of)'},
		{code: 'BQ', name: 'Bonaire, Sint Eustatius and Saba'},
		{code: 'BA', name: 'Bosnia and Herzegovina'},
		{code: 'BW', name: 'Botswana'},
		{code: 'BV', name: 'Bouvet Island'},
		{code: 'BR', name: 'Brazil'},
		{code: 'IO', name: 'British Indian Ocean Territory'},
		{code: 'BN', name: 'Brunei Darussalam'},
		{code: 'BG', name: 'Bulgaria'},
		{code: 'BF', name: 'Burkina Faso'},
		{code: 'BI', name: 'Burundi'},
		{code: 'CV', name: 'Cabo Verde'},
		{code: 'KH', name: 'Cambodia'},
		{code: 'CM', name: 'Cameroon'},
		{code: 'CA', name: 'Canada'},
		{code: 'KY', name: 'Cayman Islands'},
		{code: 'CF', name: 'Central African Republic'},
		{code: 'TD', name: 'Chad'},
		{code: 'CL', name: 'Chile'},
		{code: 'CN', name: 'China'},
		{code: 'CX', name: 'Christmas Island'},
		{code: 'CC', name: 'Cocos (Keeling) Islands'},
		{code: 'CO', name: 'Colombia'},
		{code: 'KM', name: 'Comoros'},
		{code: 'CG', name: 'Congo'},
		{code: 'CD', name: 'Congo (Democratic Republic of the)'},
		{code: 'CK', name: 'Cook Islands'},
		{code: 'CR', name: 'Costa Rica'},
		{code: 'CI', name: 'CĂ´te d\'Ivoire'},
		{code: 'HR', name: 'Croatia'},
		{code: 'CU', name: 'Cuba'},
		{code: 'CW', name: 'Curaçao'},
		{code: 'CY', name: 'Cyprus'},
		{code: 'CZ', name: 'Czech Republic'},
		{code: 'DK', name: 'Denmark'},
		{code: 'DJ', name: 'Djibouti'},
		{code: 'DM', name: 'Dominica'},
		{code: 'DO', name: 'Dominican Republic'},
		{code: 'EC', name: 'Ecuador'},
		{code: 'EG', name: 'Egypt'},
		{code: 'SV', name: 'El Salvador'},
		{code: 'GQ', name: 'Equatorial Guinea'},
		{code: 'ER', name: 'Eritrea'},
		{code: 'EE', name: 'Estonia'},
		{code: 'ET', name: 'Ethiopia'},
		{code: 'FK', name: 'Falkland Islands (Malvinas)'},
		{code: 'FO', name: 'Faroe Islands'},
		{code: 'FJ', name: 'Fiji (Republic of)'},
		{code: 'FI', name: 'Finland'},
		{code: 'FR', name: 'France'},
		{code: 'GF', name: 'French Guiana'},
		{code: 'PF', name: 'French Polynesia'},
		{code: 'TF', name: 'French Southern Territories'},
		{code: 'GA', name: 'Gabon'},
		{code: 'GM', name: 'Gambia'},
		{code: 'GE', name: 'Georgia'},
		{code: 'DE', name: 'Germany'},
		{code: 'GH', name: 'Ghana'},
		{code: 'GI', name: 'Gibraltar'},
		{code: 'GR', name: 'Greece'},
		{code: 'GL', name: 'Greenland'},
		{code: 'GD', name: 'Grenada'},
		{code: 'GP', name: 'Guadeloupe'},
		{code: 'GU', name: 'Guam'},
		{code: 'GT', name: 'Guatemala'},
		{code: 'GG', name: 'Guernsey'},
		{code: 'GN', name: 'Guinea'},
		{code: 'GW', name: 'Guinea-Bissau'},
		{code: 'GY', name: 'Guyana'},
		{code: 'HT', name: 'Haiti'},
		{code: 'HM', name: 'Heard Island and McDonald Islands'},
		{code: 'VA', name: 'Holy See'},
		{code: 'HN', name: 'Honduras'},
		{code: 'HK', name: 'Hong Kong'},
		{code: 'HU', name: 'Hungary'},
		{code: 'IS', name: 'Iceland'},
		{code: 'IN', name: 'India'},
		{code: 'ID', name: 'Indonesia'},
		{code: 'IR', name: 'Iran (Islamic Republic of)'},
		{code: 'IQ', name: 'Iraq'},
		{code: 'IE', name: 'Ireland'},
		{code: 'IM', name: 'Isle of Man'},
		{code: 'IL', name: 'Israel'},
		{code: 'IT', name: 'Italy'},
		{code: 'JM', name: 'Jamaica'},
		{code: 'JP', name: 'Japan'},
		{code: 'JE', name: 'Jersey'},
		{code: 'JO', name: 'Jordan'},
		{code: 'KZ', name: 'Kazakhstan'},
		{code: 'KE', name: 'Kenya'},
		{code: 'KI', name: 'Kiribati'},
		{code: 'KP', name: 'Korea (Democratic People\'s Republic of)'},
		{code: 'KR', name: 'Korea (Republic of)'},
		{code: 'KW', name: 'Kuwait'},
		{code: 'KG', name: 'Kyrgyzstan'},
		{code: 'LA', name: 'Lao People\'s Democratic Republic'},
		{code: 'LV', name: 'Latvia'},
		{code: 'LB', name: 'Lebanon'},
		{code: 'LS', name: 'Lesotho'},
		{code: 'LR', name: 'Liberia'},
		{code: 'LY', name: 'Libya'},
		{code: 'LI', name: 'Liechtenstein'},
		{code: 'LT', name: 'Lithuania'},
		{code: 'LU', name: 'Luxembourg'},
		{code: 'MO', name: 'Macao'},
		{code: 'MK', name: 'Macedonia (the former Yugoslav Republic of)'},
		{code: 'MG', name: 'Madagascar'},
		{code: 'MW', name: 'Malawi'},
		{code: 'MY', name: 'Malaysia'},
		{code: 'MV', name: 'Maldives'},
		{code: 'ML', name: 'Mali'},
		{code: 'MT', name: 'Malta'},
		{code: 'MH', name: 'Marshall Islands'},
		{code: 'MQ', name: 'Martinique'},
		{code: 'MR', name: 'Mauritania'},
		{code: 'MU', name: 'Mauritius'},
		{code: 'YT', name: 'Mayotte'},
		{code: 'MX', name: 'Mexico'},
		{code: 'FM', name: 'Micronesia (Federated States of)'},
		{code: 'MD', name: 'Moldova (Republic of)'},
		{code: 'MC', name: 'Monaco'},
		{code: 'MN', name: 'Mongolia'},
		{code: 'ME', name: 'Montenegro'},
		{code: 'MS', name: 'Montserrat'},
		{code: 'MA', name: 'Morocco'},
		{code: 'MZ', name: 'Mozambique'},
		{code: 'MM', name: 'Myanmar'},
		{code: 'NA', name: 'Namibia'},
		{code: 'NR', name: 'Nauru'},
		{code: 'NP', name: 'Nepal'},
		{code: 'NL', name: 'Netherlands'},
		{code: 'NC', name: 'New Caledonia'},
		{code: 'NZ', name: 'New Zealand'},
		{code: 'NI', name: 'Nicaragua'},
		{code: 'NE', name: 'Niger'},
		{code: 'NG', name: 'Nigeria'},
		{code: 'NU', name: 'Niue'},
		{code: 'NF', name: 'Norfolk Island'},
		{code: 'MP', name: 'Northern Mariana Islands'},
		{code: 'NO', name: 'Norway'},
		{code: 'OM', name: 'Oman'},
		{code: 'PK', name: 'Pakistan'},
		{code: 'PW', name: 'Palau'},
		{code: 'PS', name: 'Palestine, State of'},
		{code: 'PA', name: 'Panama'},
		{code: 'PG', name: 'Papua New Guinea'},
		{code: 'PY', name: 'Paraguay'},
		{code: 'PE', name: 'Peru'},
		{code: 'PH', name: 'Philippines'},
		{code: 'PN', name: 'Pitcairn'},
		{code: 'PL', name: 'Poland'},
		{code: 'PT', name: 'Portugal'},
		{code: 'PR', name: 'Puerto Rico'},
		{code: 'QA', name: 'Qatar'},
		{code: 'RE', name: 'RĂ©union'},
		{code: 'RO', name: 'Romania'},
		{code: 'RU', name: 'Russian Federation'},
		{code: 'RW', name: 'Rwanda'},
		{code: 'BL', name: 'Saint Barthélemy'},
		{code: 'SH', name: 'Saint Helena, Ascension and Tristan da Cunha'},
		{code: 'KN', name: 'Saint Kitts and Nevis'},
		{code: 'LC', name: 'Saint Lucia'},
		{code: 'MF', name: 'Saint Martin (French part)'},
		{code: 'PM', name: 'Saint Pierre and Miquelon'},
		{code: 'VC', name: 'Saint Vincent and the Grenadines'},
		{code: 'WS', name: 'Samoa'},
		{code: 'SM', name: 'San Marino'},
		{code: 'ST', name: 'Sao Tome and Principe'},
		{code: 'SA', name: 'Saudi Arabia'},
		{code: 'SN', name: 'Senegal'},
		{code: 'RS', name: 'Serbia'},
		{code: 'SC', name: 'Seychelles'},
		{code: 'SL', name: 'Sierra Leone'},
		{code: 'SG', name: 'Singapore'},
		{code: 'SX', name: 'Sint Maarten (Dutch part)'},
		{code: 'SK', name: 'Slovakia'},
		{code: 'SI', name: 'Slovenia'},
		{code: 'SB', name: 'Solomon Islands'},
		{code: 'SO', name: 'Somalia'},
		{code: 'ZA', name: 'South Africa'},
		{code: 'GS', name: 'South Georgia and the South Sandwich Islands'},
		{code: 'SS', name: 'South Sudan'},
		{code: 'ES', name: 'Spain'},
		{code: 'LK', name: 'Sri Lanka'},
		{code: 'SD', name: 'Sudan'},
		{code: 'SR', name: 'Suriname'},
		{code: 'SJ', name: 'Svalbard and Jan Mayen'},
		{code: 'SZ', name: 'Swaziland'},
		{code: 'SE', name: 'Sweden'},
		{code: 'CH', name: 'Switzerland'},
		{code: 'SY', name: 'Syrian Arab Republic'},
		{code: 'TW', name: 'Taiwan, Province of China'},
		{code: 'TJ', name: 'Tajikistan'},
		{code: 'TZ', name: 'Tanzania, United Republic of'},
		{code: 'TH', name: 'Thailand'},
		{code: 'TL', name: 'Timor-Leste'},
		{code: 'TG', name: 'Togo'},
		{code: 'TK', name: 'Tokelau'},
		{code: 'TO', name: 'Tonga'},
		{code: 'TT', name: 'Trinidad and Tobago'},
		{code: 'TN', name: 'Tunisia'},
		{code: 'TR', name: 'Turkey'},
		{code: 'TM', name: 'Turkmenistan'},
		{code: 'TC', name: 'Turks and Caicos Islands'},
		{code: 'TV', name: 'Tuvalu'},
		{code: 'UG', name: 'Uganda'},
		{code: 'UA', name: 'Ukraine'},
		{code: 'AE', name: 'United Arab Emirates'},
		{code: 'GB', name: 'United Kingdom of Great Britain and Northern Ireland'},
		{code: 'US', name: 'United States of America'},
		{code: 'UM', name: 'United States Minor Outlying Islands'},
		{code: 'UY', name: 'Uruguay'},
		{code: 'UZ', name: 'Uzbekistan'},
		{code: 'VU', name: 'Vanuatu'},
		{code: 'VE', name: 'Venezuela (Bolivarian Republic of)'},
		{code: 'VN', name: 'Vietnam'},
		{code: 'VG', name: 'Virgin Islands (British)'},
		{code: 'VI', name: 'Virgin Islands (U.S.)'},
		{code: 'WF', name: 'Wallis and Futuna'},
		{code: 'EH', name: 'Western Sahara'},
		{code: 'YE', name: 'Yemen'},
		{code: 'ZM', name: 'Zambia'},
		{code: 'ZW', name: 'Zimbabwe'}
	];

	var codes = {};

	for (var i = 0; i < list.length; ++i) {
		var entry = list[i];
		codes[entry.code] = entry;
	}
	
	// public methods
	
	this.getList= function() {
		return list;
	};

	this.getEntry = function(code) {
		return codes[code] || null;
	};
};

// Example usage:

var pl = Countries.getEntry('PL');
var gb = Countries.getEntry('GB');
var us = Countries.getEntry('US');
var jp = Countries.getEntry('JP');

console.log(pl.name); // Poland
console.log(gb.name); // United Kingdom of Great Britain and Northern Ireland
console.log(us.name); // United States of America
console.log(jp.name); // Japan

Country codes with many alternative names

This section contains many alternative country names that are related with same country code.

The main idea of the country names is to organise them starting from simplest, across to some other alternatives, going to longest official names.

TODO: list requires to add more alternative names in future.

// ONLINE-RUNNER:browser;

var Countries = new function() {

	// https://en.wikipedia.org/wiki/ISO_3166-1

	var list = [
		{code: 'AF', names: ['Afghanistan']},
		{code: 'AX', names: ['Ă…land Islands']},
		{code: 'AL', names: ['Albania']},
		{code: 'DZ', names: ['Algeria']},
		{code: 'AS', names: ['American Samoa']},
		{code: 'AD', names: ['Andorra']},
		{code: 'AO', names: ['Angola']},
		{code: 'AI', names: ['Anguilla']},
		{code: 'AQ', names: ['Antarctica']},
		{code: 'AG', names: ['Antigua and Barbuda']},
		{code: 'AR', names: ['Argentina']},
		{code: 'AM', names: ['Armenia']},
		{code: 'AW', names: ['Aruba']},
		{code: 'AU', names: ['Australia']},
		{code: 'AT', names: ['Austria']},
		{code: 'AZ', names: ['Azerbaijan']},
		{code: 'BS', names: ['Bahamas']},
		{code: 'BH', names: ['Bahrain']},
		{code: 'BD', names: ['Bangladesh']},
		{code: 'BB', names: ['Barbados']},
		{code: 'BY', names: ['Belarus']},
		{code: 'BE', names: ['Belgium']},
		{code: 'BZ', names: ['Belize']},
		{code: 'BJ', names: ['Benin']},
		{code: 'BM', names: ['Bermuda']},
		{code: 'BT', names: ['Bhutan']},
		{code: 'BO', names: ['Bolivia', 'Bolivia (Plurinational State of)', 'Plurinational State of Bolivia']},
		{code: 'BQ', names: ['Bonaire, Sint Eustatius and Saba']},
		{code: 'BA', names: ['Bosnia and Herzegovina']},
		{code: 'BW', names: ['Botswana']},
		{code: 'BV', names: ['Bouvet Island']},
		{code: 'BR', names: ['Brazil']},
		{code: 'IO', names: ['British Indian Ocean Territory']},
		{code: 'BN', names: ['Brunei', 'Nation of Brunei, the Abode of Peace', 'Brunei Darussalam']},
		{code: 'BG', names: ['Bulgaria']},
		{code: 'BF', names: ['Burkina Faso']},
		{code: 'BI', names: ['Burundi']},
		{code: 'CV', names: ['Cabo Verde', 'Cape Verde', 'Republic of Cabo Verde']},
		{code: 'KH', names: ['Cambodia']},
		{code: 'CM', names: ['Cameroon']},
		{code: 'CA', names: ['Canada']},
		{code: 'KY', names: ['Cayman Islands']},
		{code: 'CF', names: ['Central African Republic']},
		{code: 'TD', names: ['Chad']},
		{code: 'CL', names: ['Chile']},
		{code: 'CN', names: ['China', 'PRC', 'People\'s Republic of China']},
		{code: 'CX', names: ['Christmas Island']},
		{code: 'CC', names: ['Cocos (Keeling) Islands']},
		{code: 'CO', names: ['Colombia']},
		{code: 'KM', names: ['Comoros']},
		{code: 'CG', names: ['Congo', 'Republic of the Congo']},
		{code: 'CD', names: ['Congo (Democratic Republic of the)', 'DRC', 'Congo-Kinshasa', 'DR Congo', 'the DROC', 'the Congo', 'Democratic Republic of the Congo']},
		{code: 'CK', names: ['Cook Islands']},
		{code: 'CR', names: ['Costa Rica']},
		{code: 'CI', names: ['CĂ´te d\'Ivoire', 'Ivory Coast', 'Republic of CĂ´te d\'Ivoire']},
		{code: 'HR', names: ['Croatia']},
		{code: 'CU', names: ['Cuba']},
		{code: 'CW', names: ['Curaçao']},
		{code: 'CY', names: ['Cyprus']},
		{code: 'CZ', names: ['Czech Republic']},
		{code: 'DK', names: ['Denmark']},
		{code: 'DJ', names: ['Djibouti']},
		{code: 'DM', names: ['Dominica']},
		{code: 'DO', names: ['Dominican Republic']},
		{code: 'EC', names: ['Ecuador']},
		{code: 'EG', names: ['Egypt']},
		{code: 'SV', names: ['El Salvador']},
		{code: 'GQ', names: ['Equatorial Guinea']},
		{code: 'ER', names: ['Eritrea']},
		{code: 'EE', names: ['Estonia']},
		{code: 'ET', names: ['Ethiopia']},
		{code: 'FK', names: ['Falkland Islands (Malvinas)']},
		{code: 'FO', names: ['Faroe Islands']},
		{code: 'FJ', names: ['Fiji', 'Fiji (Republic of)', 'Republic of Fiji']},
		{code: 'FI', names: ['Finland']},
		{code: 'FR', names: ['France']},
		{code: 'GF', names: ['French Guiana']},
		{code: 'PF', names: ['French Polynesia']},
		{code: 'TF', names: ['French Southern Territories']},
		{code: 'GA', names: ['Gabon']},
		{code: 'GM', names: ['Gambia']},
		{code: 'GE', names: ['Georgia']},
		{code: 'DE', names: ['Germany']},
		{code: 'GH', names: ['Ghana']},
		{code: 'GI', names: ['Gibraltar']},
		{code: 'GR', names: ['Greece']},
		{code: 'GL', names: ['Greenland']},
		{code: 'GD', names: ['Grenada']},
		{code: 'GP', names: ['Guadeloupe']},
		{code: 'GU', names: ['Guam']},
		{code: 'GT', names: ['Guatemala']},
		{code: 'GG', names: ['Guernsey']},
		{code: 'GN', names: ['Guinea']},
		{code: 'GW', names: ['Guinea-Bissau']},
		{code: 'GY', names: ['Guyana']},
		{code: 'HT', names: ['Haiti']},
		{code: 'HM', names: ['Heard Island and McDonald Islands']},
		{code: 'VA', names: ['The Vatican', 'Vatican City', 'Vatican City State', 'Holy See']},
		{code: 'HN', names: ['Honduras']},
		{code: 'HK', names: ['Hong Kong']},
		{code: 'HU', names: ['Hungary']},
		{code: 'IS', names: ['Iceland']},
		{code: 'IN', names: ['India']},
		{code: 'ID', names: ['Indonesia']},
		{code: 'IR', names: ['Iran', 'Iran (Islamic Republic of)']},
		{code: 'IQ', names: ['Iraq']},
		{code: 'IE', names: ['Ireland']},
		{code: 'IM', names: ['Isle of Man']},
		{code: 'IL', names: ['Israel']},
		{code: 'IT', names: ['Italy']},
		{code: 'JM', names: ['Jamaica']},
		{code: 'JP', names: ['Japan']},
		{code: 'JE', names: ['Jersey']},
		{code: 'JO', names: ['Jordan']},
		{code: 'KZ', names: ['Kazakhstan']},
		{code: 'KE', names: ['Kenya']},
		{code: 'KI', names: ['Kiribati']},
		{code: 'KP', names: ['North Korea', 'DPRK', 'DPR Korea', 'Korea (Democratic People\'s Republic of)', 'Democratic People\'s Republic of Korea']},
		{code: 'KR', names: ['South Korea', 'ROK', 'Korea (Republic of)', 'Republic of Korea']},
		{code: 'KW', names: ['Kuwait']},
		{code: 'KG', names: ['Kyrgyzstan']},
		{code: 'LA', names: ['Laos', 'Lao People\'s Democratic Republic']},
		{code: 'LV', names: ['Latvia']},
		{code: 'LB', names: ['Lebanon']},
		{code: 'LS', names: ['Lesotho']},
		{code: 'LR', names: ['Liberia']},
		{code: 'LY', names: ['Libya']},
		{code: 'LI', names: ['Liechtenstein']},
		{code: 'LT', names: ['Lithuania']},
		{code: 'LU', names: ['Luxembourg']},
		{code: 'MO', names: ['Macao']},
		{code: 'MK', names: ['Macedonia', 'Macedonia (the former Yugoslav Republic of)', 'North Macedonia', 'Republic of North Macedonia']},
		{code: 'MG', names: ['Madagascar']},
		{code: 'MW', names: ['Malawi']},
		{code: 'MY', names: ['Malaysia']},
		{code: 'MV', names: ['Maldives']},
		{code: 'ML', names: ['Mali']},
		{code: 'MT', names: ['Malta']},
		{code: 'MH', names: ['Marshall Islands']},
		{code: 'MQ', names: ['Martinique']},
		{code: 'MR', names: ['Mauritania']},
		{code: 'MU', names: ['Mauritius']},
		{code: 'YT', names: ['Mayotte']},
		{code: 'MX', names: ['Mexico']},
		{code: 'FM', names: ['Micronesia', 'FSM', 'Micronesia (Federated States of)', 'Federated States of Micronesia']},
		{code: 'MD', names: ['Moldova', 'Moldova (Republic of)', 'Republic of Moldova']},
		{code: 'MC', names: ['Monaco']},
		{code: 'MN', names: ['Mongolia']},
		{code: 'ME', names: ['Montenegro']},
		{code: 'MS', names: ['Montserrat']},
		{code: 'MA', names: ['Morocco']},
		{code: 'MZ', names: ['Mozambique']},
		{code: 'MM', names: ['Myanmar']},
		{code: 'NA', names: ['Namibia']},
		{code: 'NR', names: ['Nauru']},
		{code: 'NP', names: ['Nepal']},
		{code: 'NL', names: ['Netherlands']},
		{code: 'NC', names: ['New Caledonia']},
		{code: 'NZ', names: ['New Zealand']},
		{code: 'NI', names: ['Nicaragua']},
		{code: 'NE', names: ['Niger']},
		{code: 'NG', names: ['Nigeria']},
		{code: 'NU', names: ['Niue']},
		{code: 'NF', names: ['Norfolk Island']},
		{code: 'MP', names: ['Northern Mariana Islands']},
		{code: 'NO', names: ['Norway']},
		{code: 'OM', names: ['Oman']},
		{code: 'PK', names: ['Pakistan']},
		{code: 'PW', names: ['Palau']},
		{code: 'PS', names: ['Palestine', 'Palestine, State of', 'State of Palestine']},
		{code: 'PA', names: ['Panama']},
		{code: 'PG', names: ['Papua New Guinea']},
		{code: 'PY', names: ['Paraguay']},
		{code: 'PE', names: ['Peru']},
		{code: 'PH', names: ['Philippines']},
		{code: 'PN', names: ['Pitcairn']},
		{code: 'PL', names: ['Poland']},
		{code: 'PT', names: ['Portugal']},
		{code: 'PR', names: ['Puerto Rico']},
		{code: 'QA', names: ['Qatar']},
		{code: 'RE', names: ['RĂ©union']},
		{code: 'RO', names: ['Romania']},
		{code: 'RU', names: ['Russia', 'Russian Federation']},
		{code: 'RW', names: ['Rwanda']},
		{code: 'BL', names: ['Saint Barthélemy']},
		{code: 'SH', names: ['Saint Helena, Ascension and Tristan da Cunha']},
		{code: 'KN', names: ['Saint Kitts and Nevis']},
		{code: 'LC', names: ['Saint Lucia']},
		{code: 'MF', names: ['Saint Martin (French part)']},
		{code: 'PM', names: ['Saint Pierre and Miquelon']},
		{code: 'VC', names: ['Saint Vincent and the Grenadines']},
		{code: 'WS', names: ['Samoa']},
		{code: 'SM', names: ['San Marino']},
		{code: 'ST', names: ['Sao Tome and Principe', 'Saint Thomas and Prince', 'São Tomé and Príncipe', 'Democratic Republic of São Tomé and Príncipe']},
		{code: 'SA', names: ['Saudi Arabia']},
		{code: 'SN', names: ['Senegal']},
		{code: 'RS', names: ['Serbia']},
		{code: 'SC', names: ['Seychelles']},
		{code: 'SL', names: ['Sierra Leone']},
		{code: 'SG', names: ['Singapore']},
		{code: 'SX', names: ['Sint Maarten (Dutch part)']},
		{code: 'SK', names: ['Slovakia']},
		{code: 'SI', names: ['Slovenia']},
		{code: 'SB', names: ['Solomon Islands']},
		{code: 'SO', names: ['Somalia']},
		{code: 'ZA', names: ['South Africa']},
		{code: 'GS', names: ['South Georgia and the South Sandwich Islands']},
		{code: 'SS', names: ['South Sudan']},
		{code: 'ES', names: ['Spain']},
		{code: 'LK', names: ['Sri Lanka']},
		{code: 'SD', names: ['Sudan']},
		{code: 'SR', names: ['Suriname']},
		{code: 'SJ', names: ['Svalbard and Jan Mayen']},
		{code: 'SZ', names: ['Swaziland']},
		{code: 'SE', names: ['Sweden']},
		{code: 'CH', names: ['Switzerland']},
		{code: 'SY', names: ['Syria', 'Syrian Arab Republic']},
		{code: 'TW', names: ['Taiwan', 'Taiwan, Province of China', 'Republic of China (Taiwan)']},
		{code: 'TJ', names: ['Tajikistan']},
		{code: 'TZ', names: ['Tanzania', 'Tanzania, United Republic of', 'United Republic of Tanzania']},
		{code: 'TH', names: ['Thailand']},
		{code: 'TL', names: ['Timor-Leste']},
		{code: 'TG', names: ['Togo']},
		{code: 'TK', names: ['Tokelau']},
		{code: 'TO', names: ['Tonga']},
		{code: 'TT', names: ['Trinidad and Tobago']},
		{code: 'TN', names: ['Tunisia']},
		{code: 'TR', names: ['Turkey']},
		{code: 'TM', names: ['Turkmenistan']},
		{code: 'TC', names: ['Turks and Caicos Islands']},
		{code: 'TV', names: ['Tuvalu']},
		{code: 'UG', names: ['Uganda']},
		{code: 'UA', names: ['Ukraine']},
		{code: 'AE', names: ['United Arab Emirates']},
		{code: 'GB', names: ['United Kingdom', 'UK', 'U.K.', 'United Kingdom of Great Britain and Northern Ireland']},
		{code: 'US', names: ['United States', 'US', 'U.S.', 'USA', 'America', 'United States of America']},
		{code: 'UM', names: ['United States Minor Outlying Islands']},
		{code: 'UY', names: ['Uruguay']},
		{code: 'UZ', names: ['Uzbekistan']},
		{code: 'VU', names: ['Vanuatu']},
		{code: 'VE', names: ['Venezuela', 'Venezuela (Bolivarian Republic of)']},
		{code: 'VN', names: ['Vietnam']},
		{code: 'VG', names: ['Virgin Islands (British)']},
		{code: 'VI', names: ['Virgin Islands (U.S.)']},
		{code: 'WF', names: ['Wallis and Futuna']},
		{code: 'EH', names: ['Western Sahara']},
		{code: 'YE', names: ['Yemen']},
		{code: 'ZM', names: ['Zambia']},
		{code: 'ZW', names: ['Zimbabwe']}
	];

	var codes = {};
	var names = {};

	for (var i = 0; i < list.length; ++i) {
		var entry = list[i];
		var keys = entry.names;
		for (var j = 0; j < keys.length; ++j) {
			var key = keys[j].toLocaleLowerCase();
			names[key] = entry;
		}
		codes[entry.code] = entry;
	}
	
	// public methods
	
	this.getList= function() {
		return list;
	};

	this.getEntryByCode = function(code) {
		return codes[code] || null;
	};

	this.getEntryByName = function(name) {
		var key = name.toLocaleLowerCase();
		return names[key] || null;
	};
};

// Example usage:

var pl = Countries.getEntryByCode('PL');
var gb = Countries.getEntryByCode('GB');
var us = Countries.getEntryByName('USA');
var jp = Countries.getEntryByName('Japan');

console.log(pl.names); // Poland
console.log(gb.names); // United Kingdom,UK,U.K.,United Kingdom of Great Britain and Northern Ireland
console.log(us.names); // United States,US,U.S.,USA,America,United States of America
console.log(jp.names); // Japan
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join