I have been looking for a solution to this problem but have come up empty. It seems that some people have similar issues, however they have syntax errors that make their problem easy to correct.
I am defining an array and then below where the array is defined, I have a method. The method has a forEach that I am pushing objects into the array. When console logging the array is fully populated within the loop, but once outside of the loop, the array is empty again. Below is my code snippet
var arr = [];
function getObjects(context, done) {
request(request).then((objs) => {
objs.result.forEach((obj) => {
var obj = {
key1: med.medication,
key2: med.timeOfDosage1,
key3: med.timeOfDosage2
}
arr.push(obj)
console.log(arr)//console.log shows array full of objects
})
})
};
console.log("The new arr array: " ,arr) //console.log shows empty array