The following is my code
let icsFileData = [];
icsFileData = filterAttachmentArray.map(async(file) => {
let buff = new Buffer(file.data, 'base64');
let text = buff.toString('ascii');
const data = await ical.async.parseICS(text);
const objectKeys = Object.values(data);
const filterObj =
objectKeys.length === 1 || objectKeys[0].type === 'VEVENT' ? objectKeys[0] : objectKeys[1];
const desiredObj = {
subject: filterObj.summary.val ? filterObj.summary.val : filterObj.summary,
description: filterObj.description.val ? filterObj.description.val : filterObj.description,
dateStart: moment(filterObj.start).format('YYYY-MM-DDTHH:mm:ss\\Z'),
dateEnd: moment(filterObj.end).format('YYYY-MM-DDTHH:mm:ss\\Z'),
organizer: filterObj.organizer.params.EMAIL ?
filterObj.organizer.params.EMAIL :
filterObj.organizer.val.split('mailto:').join(''),
invites: filterObj.attendee.length === undefined ?
filterObj.attendee.params.EMAIL ?
filterObj.attendee.params.EMAIL :
filterObj.attendee.val.split('mailto:').join('') :
filterObj.attendee.map(
(invite) =>
invite.params.EMAIL ? invite.params.EMAIL : invite.val.split('mailto:').join('')
),
location: filterObj.location.val ? filterObj.location.val : filterObj.location
};
icsFileData.push(desiredObj);
});
//const icsFileDataArray = await Promise.all(icsFileData);
console.log('jhgjhgjhgj: ', await icsFileData);
Please check what is the issue, I tried many times always get the same result.
Here is the result this code always returns me
[ Promise { <pending> } ]
Promise{}means that you have to use .then() to check the value. Use something like thisconst returnFromAwait = await icsFileData();then tryreturnFromAwait.then(res => console.log(res));