javascript - 使用字符串键映射嵌套的 JavaScript 对象,然后过滤列表
问题描述
我很难通过带有字符串和对象的嵌套对象进行映射,试图获取数组中“数量”值的列表,以便我可以过滤掉。
数据如下所示:
const data = {
'123': {
'name': 'Part 1',
'size': '20',
'qty' : '50'
},
'5678' : {
'name': 'Part 2',
'size': '15',
'qty' : '60'
},
'9810' : {
'name': 'Part 2',
'size': '15',
'qty' : '120'
},
}
// my code I tried:
const getValue = Object.key(data).map(i=> [i].qty) //undefined
// expect return ['50','60','120']
const items = ['4','120','5']
// Expecting remove '120' from this list, because the getValue should have '120' in the array.
const filterItem = items.filter(i => i !== getValue)
谢谢您的帮助!
解决方案
像这样试试
Object.keys(data).map(i => data[i].qty)
推荐阅读
- r - 如何在 R 上将患病人群细分为性别 - 微生物组
- c# - 如何在 C# 中为 SDL2 加载 DLL?(DLLImport 的问题)
- reactjs - Axios如何在componentDidMount中异步获取数据
- python - WinError 2:系统在Python中找不到FluidSynth指定的文件?
- sql-server - mdf 无法打开,因为版本是 661,我的数据库支持 665
- python - Django 通道错误:没有消息类型 websocket.receive 的处理程序
- javascript - 如何从 Selenium 访问更改 HTML
- jquery - 单击一个特定 TD 时显示/隐藏表格 TD
- python - 无法导入名称,来自 python-telegram-bot 的错误
- javascript - 清除跨度中的消息