问题描述
我创建了这个包含键/值对的JavaScript对象。键是州,值是每个州内城市的数组。
I created this JavaScript object that contains key/value pairs. The keys are the states and the values are arrays of the cities within each state.
我在JSFiddle上包括了到我的代码的链接,但是对象的基本结构如下:
I have included a link to my code on JSFiddle, but the basic structure of my object looks like this:
var location = {
"Key":[],
"Key":[],
}
-
我是否正确设置了对象?
Have I set up my object correctly?
MG的键/值对出了点问题。不过,我不清楚。当我查看用颜色编码的代码时,该行的下半部分是黑色的(从', Santa Maria doSuaçuí开始,而其余部分按预期显示。
There's something wrong with the key/value pair for 'MG.' I can't figure out what, though. When I look at the color-coded code, the second half of that line is black (starting at ', "Santa Maria do Suaçuí"' while the rest displays as expected.
我将不胜感激任何能使我的装备重新运转的反馈。
I will greatly appreciate any feedback that can get my gears turning, again.
谢谢!
推荐答案
您的对象已正确设置,您可以通过以下方式访问其属性:
Your object is set up properly, you can access its properties in this way:
//for example property 'AC' at index 0
location["AC"][0] //returns Acrelândia
这篇关于javascript对象键值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!