I came across one of the problem with Async and await. Where it is returning Promise array instead of actual Array of values. I understand async await uses Promise and generators internally but wanted to understand how i can solve the below issue.
let object = [
"hello1",
"hello2",
"hello3",
"hello4"
]
async function funct(value){
return new Promise((res,rej)=> res( value + '-world'));
}
let resultArray = object.map(async (e)=>{
let result = await funct(e);
return result
})
console.log(Promise.all(resultArray).then((r)=> console.log(r)));
output is :
Promise { <pending> }
[ 'hello1-world', 'hello2-world', 'hello3-world', 'hello4-world' ]
But I am looking for actual array of values.
[ 'hello1-world', 'hello2-world', 'hello3-world', 'hello4-world' ]
Can you please suggest on this.?