Working with function which returns Promise object like on the screenshot. How I can get PromiseResult from this object?
CodePudding user response:
You can get the result of a promise by using .then() like so:
functionThatReturnsPromise().then((result) => {
//do something with result
})
CodePudding user response:
You need to use .then() function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
yourFunction().then((result) => {
console.log(result);
});
CodePudding user response:
if you run this code in your browser yo get the same structure:
function createPromise(){
return new Promise((resolve)=>{
resolve([{value:{},label:'Malmo'}])
})
}
const rta = createPromise()
rta
to get its data you can do:
rta.then(array => console.log(array[0].label))