0
var playlist = JSON.parse('{"VideoID" : {"VideoTitle" : "the title of the video"} }');

for(var video in playlist){
document.write(video + " "+ video.title +"<br>");
}

the output is : VideoID undefined

I want to the out put to be : VideoID the title of the video

1
  • video is a key, not value. There is no such property title in a String video. Commented May 8, 2014 at 21:19

2 Answers 2

2

Correct usage is:

 for(var video in playlist){
    document.write(video + " "+ playlist[video].VideoTitle +"<br>");
 }
Sign up to request clarification or add additional context in comments.

Comments

0

This should work,

var playlist = JSON.parse('{"VideoID" : {"VideoTitle" : "the title of the video"} }');

document.write(playlist.VideoID.VideoTitle);

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.