I am retrieving a json array of information using Youtube's api. I want to loop through the "items" array which is within the entire array to access each item's video ID.
results = {
"kind": "youtube#searchListResponse",
"etag": "\"bvxF-DWHx1toJotsdJBeCm43SLs/Z5vAcycCC4VZd3cPfwzTWZ_FrUQ\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "TvyWRevLG5I"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "P8iKcdh5Ims"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "tiRZ7YQKUgQ"
},
},
{
"id": {
"kind": "youtube#video",
"videoId": "mENb0jX-SD8"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "B34hQieOXZs"
}
}
]
}
This is my jquery code to loop through:
$.each(results.items, function(i, item) {
alert(items[i].id.videoId);
});
I am getting the error "Cannot read property 'length' of undefined" for some reason. Also when I try getting the length (results.items.length)to use a normal forloop, I get the same error.