【问题标题】:Youtube.Search.list(..).getItems return a String? how to easily transform or filter items?Youtube.Search.list(..).getItems 返回一个字符串?如何轻松转换或过滤项目?
【发布时间】:2021-02-26 08:31:39
【问题描述】:

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

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

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

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

【问题讨论】:

  • 请不要发布嵌入图像的源代码。对于发帖者来说,捕捉他/她的屏幕确实更容易,但对于该帖子的读者来说,在屏幕截图上工作真的很痛苦(例如,不能轻易地在该源代码上进行复制粘贴)。更不用说这违反了基本的 SO 发布指南规则。
  • 谢谢!但这次复制粘贴我的代码并没有真正相关。下次我会添加代码

标签: javascript youtube-api youtube-data-api android-youtube-api


【解决方案1】:

代码:

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'] 都是数组。

【讨论】:

    猜你喜欢
    • 2020-02-22
    • 2013-02-09
    • 2015-05-23
    • 2022-10-08
    • 2017-09-03
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多