javascript - 带有数字的对象的循环列表
问题描述
我正在遍历对象列表,但是在调用异步函数时,我得到了带有数字的对象数组,现在我无法映射数组。
{
'0': {
id: '22be325d3564d713',
name: 'dasdasdas',
affiliateIds: 2,
platformIds: 2,
campaignIds: [],
deviceOses: [],
deviceTypes: [],
countryCodes: [],
entryType: 'RED',
model: 'REVENUE_RATIO',
value: 0.01,
active: 1,
createdAt: 2020-06-11T06:00:53.000Z,
updatedAt: 2020-06-11T06:00:53.000Z
},
'1': {
id: '2891e303645099fd',
name: '',
affiliateIds: [],
platformIds: [],
campaignIds: [],
deviceOses: [],
deviceTypes: [],
countryCodes: [],
entryType: 'CNV',
model: 'REVENUE_RATIO',
value: 0.7,
active: 1,
createdAt: 2018-01-09T11:12:29.000Z,
updatedAt: 2018-01-09T11:12:29.000Z
},
我正在尝试使用
Object.map(a => a.id);
但由于数字我无法获得身份证
解决方案
Object.values()
如果您对数字属性名称不感兴趣,可以使用
const res = Object.values(data).map(({id}) => id)
console.log(res)
<script>
const data={0:{id:"22be325d3564d713",name:"dasdasdas",affiliateIds:2,platformIds:2,campaignIds:[],deviceOses:[],deviceTypes:[],countryCodes:[],entryType:"RED",model:"REVENUE_RATIO",value:.01,active:1,createdAt:"2020 - 06 - 11 T06: 00: 53.000 Z",updatedAt:"2020 - 06 - 11 T06: 00: 53.000 Z"},1:{id:"2891e303645099fd",name:"",affiliateIds:[],platformIds:[],campaignIds:[],deviceOses:[],deviceTypes:[],countryCodes:[],entryType:"CNV",model:"REVENUE_RATIO",value:.7,active:1,createdAt:"2018 - 01 - 09 T11: 12: 29.000 Z",updatedAt:"2018 - 01 - 09 T11: 12: 29.000 Z"}};
</script>
推荐阅读
- rust - 如何从合约中访问链状态数据?
- reactjs - 如何在 useState 挂钩中更新反应状态?
- laravel - 使用 Laravel、VueJS 和 Inertiajs 导出 Excel
- java - 未定义的标签:firestore 内的 loop3
- javascript - 自定义 Google 表格图表的单元格
- python - 为什么列表不保留它的价值?
- python - 将特定于类别的值分配为新列中的观察值
- firebase - 使用 Spring Boot 将图像上传到 Firebase
- redux - 使用(Material-ui + React Redux + SSR 中的 Next.js)重新渲染未更新传递的属性
- windows - 显示内存内容时,windbg 是否会自行处理内核中的分页代码?