I need to iterate over this array
, however, although it is not empty, length
of it returns 0 as you can see, does anyone know the reason?
Thescenarioisasfollows:I'mgettingJSONdatafromanAPIanditeratingovertheobjectstoputthevaluesofthepropertyIwantinthissinglearray
.Ihavetoiterateoveritnow,howeverwithsize0itbrokelogic.
//apkikey//base_urlvartags=[];varkeywordsId=[];functiontagsData(){varinput_tags=$('.chips').material_chip('data');input_tags.forEach(function(tag){tags.push(tag.tag);});}functionfindKeyWordId(){tags.forEach(function(tag){varurl=base_url+'search/keyword'+'?api_key='+apikey+'&query='+tag+'&page=1';$.getJSON(url,function(response){response.results.forEach(function(tag_obj){keywordsId.push(tag_obj.id);});});});console.log(keywordsId);};functionsearchMovies(){tagsData();findKeyWordId();console.log("Tamanho do array: " + keywordsId.length);
keywordsId.map(function(id){
var movie_url = base_url + 'keyword/' + id + '/movies' + '?api_key=' + apikey;
$.getJSON(movie_url, function(results){
console.log(results);
});
});
}