问题
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