iam traying to iterate over an array in js but it's not work and and i always get length equal 0 and when i try to access elements by index i get undefined but when i try to print my array by clg it worked well here is my code
function getData(url) {
let arr = []
fetch(url).then(response => response.json()).then(data => {
for (let index = 0; index < data.length; index++) {
arr[index] = data[index].content
}
})
console.log(arr)
}
with console.log (arr)
this the result
[]
0: "any"
1: "any"
2: "any"
3: "any"
length: 4
[[Prototype]]: Array(0)
but with console.log (arr[0])
i got
undefined
i want to get result from fetch and convert it to array and iterate over this array