I have an async loop that checks an array and if a specific value is found, it loops another array to match the founded value.
So my first implementation. I open an async loop and get my Data from Database
mergedObject = [];
array1.forEach(async (item) => {
if (item.id == 'XXX') {
const dbInfo = await readDB();
The db infos, i want to push into a array and build a json object.
dbInfo.forEach(async (itemDB) => {
object.push({
id,
name,
..
..
At the end of the loop I merge the new Object with an "older" object
mergedObject = _.map(oldObject, (objs) => {
_.assign(objs, _.find(object, {
id: objs.id,
}));
});
The Problem I have is, that inside the forEach I get the log correctly.
But If I want use the mergedObject outside the forEach (array1) I get log: []
This is my first try with async. I used Callbacks before. How can I access the mergedObject outside the forEach's?