let dataObj = [
{
Id: 1,
name: 'Alice',
Address:[{
city: 'Paris',
country: 'France'
}]
},
{
Id: 2,
name: 'Bob',
Address: [{
city: 'NYC',
country: 'USA'
},
{
city: 'Beijing',
country: 'China'
}]
}
];
async function processData() {
await Promise.all(dataObj.map(async details => {
console.log('details', JSON.stringify(details));
await Promise.all(details.Address.map(async (locations, idx) => {
console.log('ParentLocations IsUpdatedCapability',);
let result = await innerFunction();
console.log('promise resolved: ' + result)
console.log('proceeding to next step');
}));
console.log('ModifiedDetails', JSON.stringify(dataObj));
}));
}
async function innerFunction() {
return new Promise((resolve, reject) => {
let x = 0;
setTimeout(() => {
for (let j = 0; i < 10; i++) {
x++;
}
console.log('iterating completed');
resolve(x);
}, 2000);
});
}
processData();
My current output is as follows:
- details
- details
- iterating completed
- promise resolved
- proceeding to next step
- ModifiedDetails
- Iterating completed
- proceeding to the next step
- ModifiedDetails
Desired output should look like this:
- details
- iterating completed
- Promise resolved: 10
- next step
- ModifiedDetails
- details
- iterating completed
- promise resolved: 10
- proceeding to next step
- ModifiedDetails