简体   繁体   中英

Having issue when return result from promise (Im not able to use await) because it is inside a forEach [duplicate]

Current situation: I'm having a code that is handling API. And im trying to map it and return it as a string.

const C = this.functionA('ID_123').then(function(value) { 
   console.log("JR TEST 3", value.user.name); 
   return value.user.name;
});

The code above is to call the function and under 'JR TEST 3' console it return this result which is correct: JR TEST 3 USERNAME

But when I use

const C = this.functionA('ID_123').then(function(value) { 
   console.log("JR TEST 3", value.user.name); 
   return value.user.name;
});
console.log('JR TEST 4', C);

This will return me this: 在此处输入图像描述

Anyone know how to solve this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM