+ 3
How to store a value returned by a promise in a variable?
3 Antworten
+ 4
/*
The value is always there in the promise.
We just have move to next step using 'then()' to get the data.
For example in your code this can be added in the end.
*/
title.then((data) => {
console.log(data.title)
})
+ 3
Promises are another way to handle asynchronous programming in JavaScript.
When created, a promise starts in the pending state and enters the fulfilled or the rejected state depending on the result of the asynchronous work.
To handle the result of a promise, we use the .then(), .catch(), and .finally() member functions.
The .then() function takes in two handler functions, one for promise fulfillment and one for promise rejection.
The .catch() function takes in only one function and handles promise rejection.
Promise.finally() takes in one function and is called for either a promise fulfillment or rejection.
+ 1
Maybe this can help you:
https://stackoverflow.com/questions/29516390/how-to-access-the-value-of-a-promise