YouTube 動画のさまざまなプロパティを使用して配列を設定しようとしています (これは余計なことだと思われるかもしれませんが、将来的には他のソースを追加する予定です)。これらの値を JSON リクエスト内の配列に追加することはできますが、いったんそれから抜け出すと、それらは消えてしまいます。何か案は?
var socialPosts = new Array();
$.getJSON('https://gdata.youtube.com/feeds/api/videos?author=google&max-results=5&v=2&alt=jsonc&orderby=published', function(data) {
for(var i=0; i<data.data.items.length; i++) { //for each YouTube video in the request
socialPosts[i]={date:Date.parse(data.data.items[i].uploaded), title:data.data.items[i].title,source:"YouTube", thumbnail:data.data.items[i].thumbnail.hqDefault, url:'http://www.youtube.com/watch?v=' + data.data.items[i].id}; //Add values of YouTube video to array
}
console.log(socialPosts[0].date); //This returns the correct data
});
console.log(socialPosts[0].date); //This returns with undefined