How to get all the office
values from this and store it as a simple array?
var data = {
'XYZ': [{
office: 'xyz.in',
reportName: 'payroll',
event: 'open',
timestamp: '02-12-2019 00:15:29'
},
{
office: 'xyz.in',
reportName: 'payroll',
event: 'processed',
timestamp: '02-12-2019 00:15:32'
}
],
'yyy': [{
office: 'yyy.in',
reportName: 'payroll',
event: 'delivered',
timestamp: '02-12-2019 00:15:29'
},
{
office: 'yyy.in',
reportName: 'payroll',
event: 'open',
timestamp: '02-12-2019 00:15:32'
}
],
'zzz': [{
office: 'xyz.in',
reportName: 'payroll',
event: 'delivered',
timestamp: '02-12-2019 00:15:29'
},
{
office: 'xyz.in',
reportName: 'payroll',
event: 'open',
timestamp: '02-12-2019 00:15:32'
}
]
}
The output should be like:
officesArray = ['xyz.in', 'yyy.in', 'xyz.in']
my code is
var Office = (Object.entries(grpDatas).flatMap(([k, v]) => (v.forEach(({office})=> office))))
It prints array of undefined
.