This question has already been answered:
This code should send a request to the server and receive an object in which response.data is an array of numbers. In the first case (console.log (dataChart)), the array is normally output to the console, in the second case, undefined is displayed. What do Schaub does it work normally?
var dataChart; axios.get('https://xxxxxxxx.xx/handle.php?method=getStat') .then(function (response){ console.log(response); dataChart = response.data; console.log(dataChart); //N1! здесь нормально выводит массив }) .catch(function (error) { // handle error console.log(error); }) .then(function () { // always executed }); console.log(dataChart); //N2! undefined
console.log(dataChart); //N2! undefinedconsole.log(dataChart); //N2! undefinedconsole.log(dataChart); //N2! undefinedis executed beforedataChart = response.data;- Stranger in the Q