Here is my problem:
My main function:
const mainFunction = () => {
const reports = JSON.parse($sessionStorage.datas);
// reports contains array of objects.
// consider i have two objects inside one array, so the loop will execute two times now
reports.forEach((item) => {
this.openReport(item);
});
};
mainFunction();
openReport function:
this.openReport = (report) => {
console.log('openReport working');
// some async functions will be here
// ajax calls
this.openTab(report);
};
openTab function:
this.openTab = (report) => {
console.log('handleOpenTab function working');
}
Output:
// Now i have two objects, so forEach works two times.
'openReport working'
'openReport working'
'handleOpenTab function working'
'handleOpenTab function working'
My expected output :
'openReport working'
'handleOpenTab function working'
'openReport working'
'handleOpenTab function working'
How to achieve this? i am unable to use async await inside my forEach function, because using old node version.
If its possible to use async/await for this problem, i will try to upgrade my node version.