I have an array like this
let result = [{id:1,name:'test',dealValue:'ds',dealType:2},{id:2,name:'test1',dealValue:'ds',dealType:4}];
I am looping the above array to call another function which is also a promise after each iteration I need to add the value as a new item in the current array.
let temp = [];
result.forEach((element, index) => {
//build the promise
temp.push(getAmount(element.dealValue, element.dealType));
});
//execute array of promise
let r = await Promise.all(temp);
//add new key value pair
result.forEach((element, index) => {
element.IDGfee = r[index];
});
This works fine, however, I am running two foreach loops to achieve my desired result ,is there any better way to do this??