我想用JavaScript排列吗?我的错在哪里 [英] I want toarray in JavaScript? Where is it my fault?
本文介绍了我想用JavaScript排列吗?我的错在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将此代码添加到我的页面中,并且我想在用户点击邮政编码时填写城市名称 而且我的警报没有显示
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);
推荐答案
首先,您的对象中没有名为97433
的键
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.
最后,使用console.log()
进行调试,因为alert()
强制类型并阻止UI逻辑.
Lastly, use console.log()
for debugging as alert()
coerces types and blocks the UI logic.
var myVariable = obj['97433'];
console.log(myVariable);
这篇关于我想用JavaScript排列吗?我的错在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文