0

I am using an AJAX GET request to obtain a javascript object. Serverside, it is a hashmap that consists of a String and an ArrayList of Strings. Inside the success function, I am using a for-in loop to access the data that looks like this at the moment (console.log for debugging):

for (var key in content) {
    if (content.hasOwnProperty(key)) {
        console.log(key);
    }           
 }

It displays the key correctly, but how can I access the array associated with it? If I output the response to the console, it shows "KEY: Array[13]", and I can expand it to see the contents of the array.

1
  • @BrianGerhards JSFiddle is a great tool, however this was simply me not knowing syntax. Two others were able to help me within minutes, so I do not think a JSFiddle is necessary. Commented Jul 24, 2015 at 19:44

2 Answers 2

2
for (var key in content) {
    if (content.hasOwnProperty(key)) {
        console.log(content[key]);
    }           
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I feel really dumb now. Even saw this in another question, just didn't think it was applicable to my situation. Thanks a bunch!
0

most conventional way

 for(var i=0 ; i< key.length ; i++ )
    console.log(key[i]);

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.