0

I add This code to my page and I want to complete city when user tap a zipcode and my alert dosen't show

var obj = {
  "01400": "ABERGEMENT-CLÉMENCIAT",
  "01640": "ABERGEMENT-DE-VAREY",
  "01500": "AMBÉRIEU-EN-BUGEY",
  "01330": "AMBÉRIEUX-EN-DOMBES",
  "01300": "AMBLÉON",
  "01500": "AMBRONAY",
  "01500": "AMBUTRIX",
  "01300": "ANDERT-ET-CONDON",
  "01350": "ANGLEFORT",
  "01100": "APREMONT",
  "01110": "ARANC",
  "01230": "ARANDAS",
  "01100": "ARBENT",
  "01300": "ARBIGNIEU",
  "01190": "ARBIGNY"
};
var myVariable = obj .01400;
alert(myVariable);
Ahmed Guesmi
  • 350
  • 7
  • 26

1 Answers1

5

Firstly, there is no key named 97433 in your object

Secondly, even if there was you cannot use property accesors with object keys which begin with a number. You need to use bracket notation.

Lastly, use console.log() for debugging as alert() coerces types and blocks the UI logic.

var myVariable = obj['97433'];
console.log(myVariable);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339