I am trying to create a filtered array in an array of objects. I am doing so by running case switch in a forEach and deriving a new array attaching that to a new object and pushing that object to an array stored outside of the foreach. but after running the foreach the length of the external array still shows 0 and the rest of the equation relates to the processing of said array. Its two very large blocks of code so i've tried to redact some.
let updatedDrop = []
drop.forEach(async(tollFree) => {
const zipCodes = Object.values(tollFree)[0].split(",");
let updatedList = []
const {
tracking,
mailList,
} = tollFree;
zips = await Zip.find({
"class": { "$in": zipCodes },
});
zips = zips.map(zip => zip.zip4)
switch (zipCodeSuppress) {
case "keepSelect":
(insert case switch)
break;
}
const distinct = (value, index, self) => {
return self.indexOf(value) === index;
};
updatedList = updatedList.flat()
updatedList = updatedList.filter(distinct)
const combinedCost = unitCost + postageCeiling
const dropItem = {
updatedList,
tracking,
}
updatedDrop.push(dropItem)
//console.log(dropItem)
})
console.log(updatedDrop.length)
let advJobs = [];
let cspJobs = [];
let wbJobs = [];
if (updatedDrop.length > 0){ .....
so until i am able to access the updated asynchronous data the rest of the formula is stalled. How do I do this?