I'm trying to run async map in my NodeJS server, but it is not waiting the map to finish.
let test = `Start`;
const array1 = ['A', 'B'];
array1.map( async (arr1) => {
test += ' ' + arr1;
// Just a async request for testing. Return a name
const pData = await property.getPropTotalUnitsByCompany(73);
pData.map( (propData) => {
test += ' ' + propData.PropertyName;
});
});
console.log(test);
The console output is "Start A B". It never grab the data from property.getPropTotalUnitsByCompany.
getPropTotalUnitsByCompany returns an array with a couple of properties name. It looks like the code is not waiting to process the async request.