Quiero imprimir datos de mi JSON en código HTML
<body> <div id="example"></div> <div id="testing"></div> <div id="demo"></div> </body> <script> loadDoc() function loadDoc() { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; let data= JSON.parse(this.responseText); let example = document.querySelector('#example'); example.innerHTML = JSON.stringify(data.lose[0]["Preis"]); <---- here it works, i can change the innerHTML of "example" } }; xhttp.open("GET", "lose.json"); xhttp.send(); } testing.innerHTML = JSON.stringify(data.lose[1]["Preis"]) <---- outside the function loadDoc() i dont got access to data and i cant use the JSON data. </script> </html>Entonces, mi pregunta, ¿cómo puedo obtener acceso a mis datos JSON fuera de esta función loadDoc (), porque quiero usar varias entradas del JSON importado en mi HTML?