I have written the following code to return an object transformedRes having 4 values:
Id, name, message, status
In case of status, I am getting an audits array with almost 100 elements. However, I need to fetch only the last element from audit and then the audit.msg from the last audit element
const transformedRes = {
Id: res.data.map(host => host._id),
name: res.data.map(host => host._val.hostName),
message: res.data.map(host => host._val.message),
status: res.data.map(host => {
if (host) {
const auditsMsg = host._val.audits.map(audit => audit.msg);
}
})
};