1

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.

I have included a link to my code on JSFiddle, but the basic structure of my object looks like this:

var location = {
    "Key":[],
    "Key":[], 
}

JsFiddle

  1. Have I set up my object correctly?

  2. 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.

Thank you!

2 Answers 2

3

There is nothing wrong, just a limitation of the editor, try removing one string before and you will see the color will match the next string.

One alternative, would be to write one long string with a delimiter:

'string1|string2|string3'.split('|');  // ['string1', 'string2', 'string3']
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.