Javascript: How to get list of country codes


Example: we need a Javascript list of country codes
Here the source: https://porkbun.com/account/login

Read more: How to download Javascript data as file on the client side

Step 1: go to that source website
Step 2: F12 then go to console tab
Step 3: Paste Javascript code:

var q=[];
$('[name="country"] option').map(function(b,a){var m=a.value;q.push(m);return m;})
q.shift() //remove empty
q.shift() //remove US
q = JSON.stringify(q)
var data = new Blob([q], {type: 'text/plain'});
var url = window.URL.createObjectURL(data);
var x= $('<a id="download_link" download="my_exported_file.txt" href="">Download as Text File</a>')
x.attr('href',url)
$('body').append(x)
document.getElementById('download_link').click()
x.remove();
window.URL.revokeObjectURL(url);

Now you have a text file downloaded to your computer with content:

["AF","AX","AL","DZ","AS","AD","AO","AI","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY","BE","BZ","BJ","BM","BT","BO","BQ","BA","BW","BR","IO","BN","BG","BF","BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM","CG","CD","CK","CR","CI","HR","CW","CY","CZ","DK","DJ","DM","DO","EC","EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","GF","PF","TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GG","GN","GW","GY","HT","HM","VA","HN","HK","HU","IS","IN","ID","IQ","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KE","KI","KW","KG","LA","LV","LB","LS","LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH","MQ","MR","MU","YT","MX","FM","MD","MC","MN","ME","MS","MA","MZ","MM","NA","NR","NP","NL","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM","PK","PW","PS","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO","RU","RW","BL","SH","KN","LC","MF","PM","VC","WS","SM","ST","SA","SN","RS","SC","SL","SG","SX","SK","SI","SB","SO","ZA","GS","KR","ES","LK","SD","SR","SJ","SZ","SE","CH","TW","TJ","TZ","TH","TL","TG","TK","TO","TT","TN","TR","TM","TC","TV","UG","UA","AE","GB","UM","US","UY","UZ","VU","VE","VN","VG","VI","WF","EH","YE","ZM","ZW"]

Leave a Reply