Youtube.Search.list(..).getItems return 一个字符串?如何轻松转换或过滤项目?

Youtube.Search.list(..).getItems return a String? how to easily transform or filter items?

我调用 YouTube 数据 API 并收到此错误:

searchResults.getItems().map(item => item.id.videoId)};

searchResults.getItems(...).map is not a function

items 是一个字符串?如何轻松转换或过滤 items?

代码:

var a = [0], b = [1], c = a + b;
console.log(typeof(c));

console 上产生 string。这个:

var a = {};
console.log(String(a.map));
a.map();

生成行:

undefined

连同错误信息:

TypeError: a.map is not a function

使用 var a = ""; 时会发生同样的事情。

你应该替换:

searchResults['items'] =
searchResults['items'] + nextPage['items'];

与:

searchResults['items'] =
searchResults['items'].concat(nextPage['items']);

假设searchResults['items']nextPage['items']都是数组。