javascript - Javascript数组显示不是数组错误
问题描述
我在另一个对象中有一个对象数组。当我用
t.schedules.forEach(function(item) {
console.log(item[index]);
});
它显示错误 Uncaught TypeError: t.schedules.forEach is not a function。
但我可以用 t.schedules[index];
解决方案
像这样试试。If t.schedules
is an object
then将从 thatObject.values(t.schedules)
返回。然后你可以使用array of values
object
forEach
if (typeof t.schedules == "object") {
t.schedules = Object.values(t.schedules);
}
t.schedules.forEach(function(item) {
console.log(item[index]);
});
推荐阅读
- flutter - 是否需要为 VScode 更新 Dart SDK?
- flutter - 颤动不同宽度的 PageView 页面
- oauth-2.0 - 哪一个与我的 API 应用程序一起使用,它是托管标识还是 Azure AD 服务主体
- solidity - 在我修改它后,solidity 语言合同中的数组保持为空
- python - 创建 sqlite 表并从现有列表中给出列名
- microsoft-graph-api - 使用 ms-graph 'Sites.Selected' 权限读取 Sharepoint 文档库上的角色分配
- vb.net - 将 My.Settings.PropertyValues 加载到网格中
- c++ - 通过 vcpkg 安装 cgal
- reactjs - 是的,动态数值与反应钩子形式进行比较
- azure - 使用 Az CLI/PowerShell 从 Function App 重新导入 API 管理 API