I am trying to push the output of database results into a variable called 'array'. But I get an empty value in my console at the end of the process. But inside of the 'then' function, the data is coming. the size of the data.foreach is around 30. I am using Nodejs 14 and sequelize 4.
let array=[];
data.forEach(async element => {
await SelectedTech.findAll({ where: { Requirement_id: element } }).then(async data => {
array.push(data);
}).then(async data => {
array.push(data);
});
await SelectedDomains.findAll({ where: { Requirement_id: element } }).then(async data => {
array.push(data);
}).then(async data => {
array.push(data);
});
await SelectedRoles.findAll({ where: { Requirement_id: element } }).then(async data => {
array.push(data);
}).then(async data => {
array.push(data);
});
await SelectedQualifications.findAll({ where: { Requirement_id: element } }).then(async data => {
array.push(data);
}).then(async data => {
array.push(data);
});
});
console.log(array);