0

I don't really understand so thank you for understanding. I don't know how to return the function further in the code so I can use it further in the program. When I try to display the data outside of the names I get a error that my-data is not defined

axios
.request(options)
.then(function (response) {
    // console.log(response.data.age + "   ");
    let my-data = response.data.age
    console.log(my-data) // working



})
.catch(function (error) {
    console.error(error);
})  ;
console.log(my-data) // not working
};
letbet
  • 1
  • 2
  • You can't do this synchronously. Either the caller waits for the promise, or you do a callback-style thing to get the data. – Joe Jan 06 '22 at 22:08
  • Does this answer your question? [How to return the response from an asynchronous call](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Joe Jan 06 '22 at 22:09
  • try this function from Your example with try method and delay but it returns a value : null – letbet Jan 07 '22 at 11:21

0 Answers0