I am having problems getting JSON data from an array.
I tried to print array data, but it's not working:
<div id='asd'>lalala</div>
<button onclick='myfunction()'>click me</button>
<script>
function myfunction(){
var arr = [];
fetch('https://api.blockchair.com/bitcoin-sv/blocks?a=month,median(transaction_count)')
.then(response => response.json())
.then(result => arr.push(result));
console.log(arr)
document.getElementById('asd').innerHTML = arr[0]
}
</script>
I get "undefined error".