我想使用YouTube播放列表ID检索视频ID的数组。
基本上是一个返回的函数getPlaylist(playlist)
[{'title':'Video1 Title', 'ID':'Video1 ID'},
{'title':'Video2 Title', 'ID':'Video2 ID'},
{'title':'Video3 Title', 'ID':'Video3 ID'}];
我目前有this,但是要使其返回数组中的数据将需要大量重写,而且我不确定如何处理它。
我希望能够做var stuff =
getPlaylist(ID);
,并像stuff[4].title
这样引用输入的ID,并轻松处理for循环等响应。我想用尽可能少的代码行来做到这一点,并且没有库和API(例如jQuery和youtube javascript API)。
最佳答案
在循环外创建变量
var arrayOfvideoIDs = [];
在你的循环内
for (....) {
...
list_data += '<li>'+videoID+'</li>';
arrayOfvideoIDs.push(videoID);
}
现在,您有了一个
videoID
数组
关于javascript - 从youtube播放列表ID中检索视频ID的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21667738/