JavaScriptのデバッグに関する問題JavaScriptで国リストを照会する
私は国名をそれぞれの2桁のISO国コードに変換する必要があります。この問題については、初期の国の変数を名前として、次のオブジェクトを作成しました。
var country = 'Andorra' // the input country (I had to throw in the apostrophes because of country names such as "Congo Republic of" that would recognise of as a keyword if not kept in apostrophes.)
var country_code = countrylist[country]
var countrylist = {
'Andorra': 'AD',
'United Arab Emirates': 'AE',
'Afghanistan': 'AF',
'Antigua and Barbuda': 'AG',
'Anguilla': 'AI',
'Albania': 'AL',
'Armenia': 'AM',
'Angola': 'AO',
'Antarctica': 'AQ',
'Argentina': 'AR',
'American Samoa': 'AS',
'Austria': 'AT',
[...]
};
country_codeは「AD」を受け取る必要があります。
どうしたのですか?
を初期化countrylist' 'の宣言を入れ**前**あなたがそれを使用しようとする地点。 – Pointy