0

So let's say I have use fetch to get a JSON data from a site, and then I want to append to an array, but when I tried that, the array is empty. But JSON data is not empty. Code:

var movies = [];
fetch("https://example.com/movies.json")
.then(response => response.json())
.then(data => {
    for (let i=0; i<data.length; i++) {
        movies.push(data[i]);
    }
})

// console.log(movies) => shows empty array

0 Answers0