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

浪子不回头ぞ 提交于 2020-12-15 05:22:28

问题


I call YT API and get this error: searchResults.getItems().map(item => item.id.videoId)};

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

items are a String? how can I easily transform or filter items?


回答1:


The code:

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

produces string on console. This one:

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

produces the line:

undefined

along with the error message:

TypeError: a.map is not a function

The same things happen when having var a = ""; instead.

You should replace:

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

with:

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

assuming that both searchResults['items'] and nextPage['items'] are arrays.



来源:https://stackoverflow.com/questions/64836057/youtube-search-list-getitems-return-a-string-how-to-easily-transform-or-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!