我目前有以下数据:
const data = [
{
Zone: 'Airport',
Lane: 'AIRDEL',
Capacity: '90',
Status: '80',
Spaces: '10',
LastAuditedOn: 'due',
AuditedBy: 'Ross',
FirstCollection: '-',
LastCollection: '-',
},
{
Zone: 'Arrivals',
Lane: '4',
Capacity: '10',
Status: '0',
Spaces: '10',
LastAuditedOn: '-',
AuditedBy: '-',
FirstCollection: '9:00PM',
LastCollection: '01:00AM',
},
{
Zone: 'Unknown',
Lane: 'BHX_HOLD1',
Capacity: '80',
Status: '40',
Spaces: '40',
LastAuditedOn: 'due',
AuditedBy: 'Max',
FirstCollection: '-',
LastCollection: '-',
},
]我目前正在尝试提取基于属性(区域、车道、容量)的数据作为示例。
const multiHeaderBy = 'Zone';
data.forEach((key) => {
console.log(key.find(multiHeaderBy))
});我希望值arrivals, airport, unknown出现在console.log中,但我得到了未定义。
想法?
发布于 2018-03-19 20:24:06
你必须使用[] backet而不是find函数。[] backet用于使用动态键从对象中获取值。
const multiHeaderBy = 'Zone';
data.forEach((key) => {
console.log(key[multiHeaderBy])
});https://stackoverflow.com/questions/49362747
复制相似问题