I have the function shown in the code below, I need to read the value of myArr outside the function.
var xmlhttp = new XMLHttpRequest();
var url = "https://xzssgkuhg7.execute-api.us-east-2.amazonaws.com/items/aabbccdd234";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
document.getElementById("id01").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
I tried defining the variable outside the function but it is undefined. How can I do?