javascript - 使用 map 从包含项目数组的对象中获取项目
问题描述
我有一个看起来像这样的对象:
const items = {
"data": {
"app4": [
{
"id": 36,
"name": "app1.acme.com",
"port": 9447,
"title": "Application Demo 1",
"subtitle": "bootstapping demo 1"
}
],
"app5": [
{
"id": 37,
"name": "app2.acme.com",
"port": 9448,
"title": "Application Demo 2",
"subtitle": "bootstapping demo 2"
}
],
"app6": [
{
"id": 38,
"name": "app3.acme.com",
"port": 9449,
"title": "Application Demo 3",
"subtitle": "bootstapping demo 3"
}
]
}
}
我正在尝试像这样迭代对象:
Object.entries(test.data).map(item => {
item.map(function (item) {
console.log(item[0].id)
console.log(item[0].name)
});
})
但是,虽然我可以获得 ID 和名称,但它会undefined
为每个地图回调重新调整。例如
undefined
undefined
36
undefined
undefined
undefined
37
undefined
undefined
undefined
38
undefined
解决方案
推荐阅读
- python - 使用熊猫重塑股票价格数据框后重置列索引
- spring - Spring配置文件XML bean配置需要在文件的开头
- python - 从字符串中提取特定的正则表达式结果
- amazon-web-services - 如何使用 AWS Cli 批量删除 lambda 函数
- python - Discord 音乐机器人 - ffpmeg 播放器和嵌入消息出错
- c# - 如何在 EF6 中对不同实体使用同一张表
- ruby-on-rails - Rails 6.0 迁移文件根据 Postgres 偏好转换为整数?
- or-tools - Solver.Add("x + y < 5") 约束公式的字符串表示的替代方案
- javascript - face-api.js 在隐藏视频源上使用面部表情模型
- android - 我们可以在不更改 minifyEnabled false 的情况下将应用程序上传到 Play 商店吗