Hi I am facing one issue. I need to execute one method after all nested forEach
completed using node.js. I am explaining my code below.
let jsonArr = _.get(req, ['body', 'test_suite']);
jsonArr.forEach(async ele => {
let stepsArr = ele.steps;
let devices = ele.devices;
let deviceArr = devices.split(',');
let arr = [];
deviceArr.forEach(e => {
arr.push({ 'name': e });
})
ele.devices = '';
ele.devices = arr;
stepsArr.forEach(async el => {
if (el.operation === 'PATCH' || el.operation === 'PUT' || el.operation === 'POST') {
if (el.attachments && el.attachments[0].content === '') {
fileFlag = false;
msg = '_id is mandotary for POST/PATCH/PUT operation.';
} else {
const cid = el.attachments[0].content;
const result = await findById(cid, 'useCaseFile');
if (result.status === 1 && !_.isEmpty(result.data)) {
const contentToBase64 = result.data.fileData;
el.attachments[0].content = '';
el.attachments[0].content = contentToBase64;
}
}
}
})
})
console.log('jsonArr', jsonArr)
let originalJSON = {};
originalJSON['test_suite'] = jsonArr;
originalJSON['schema'] = "hello";
originalJSON['version'] = 10;
await downloadFiles(res, originalJSON, 1);
So here I need after finishing the nested loop execution then the console
message should print and also downloadFiles
method should invoke. But as per my code before finishing loop execution console.log
is executing and also downloadFiles
method is invoking as result I am not getting the right result. Here I need after finishing the all nested loop execution the stuffs below console
message should execute.