I am trying to write a web application that fetches data from GoogleMaps API. API response is correct in the then/catch block which is;
var axios = require('axios')
var config = {
method: "get",
url: httpRequest,
header: { }
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data))
})
.catch(function(error){
console.log(error)
})
in which the console.log works perfectly fine. I want to create a local object responseData and use that object outside of the then block. Here is an example;
var axios = require('axios')
let localObject ;
var config = {
method: "get",
url: httpRequest,
header: { }
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data))
localObject = response.data;
})
.catch(function(error){
console.log(error)
})
console.log(JSON.stringify(localObject)) // Local Object undefined error
How can I assign localObject with response.data?