I am new to js and I am trying to make a loop that gathers movie titles from an api using jquery requests, and save the data in an array called arr like this:
var arr = []
var query = inp.value;
var url = `https://api.themoviedb.org/3/search/movie?api_key=${key}&query=${query}`
$.getJSON(url, function(data) {
var data = data.results;
for (var i = 0; i < 10; i++) {
var title = data[i].original_title;
arr.push(title)
}
});
console.log(arr);
console.log(arr.length);
The problem is when I try to print the new arr length is gives me a length of 0, why is this happening and how do I fix it?