Question

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

Was it helpful?

Solution

Correct usage is:

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

OTHER TIPS

This should work,

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

document.write(playlist.VideoID.VideoTitle);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top