Everyone, I have been searching up and down. Tried different methods and I am not getting this simple problem to work. Basically, I was making a call to the web API which is a collection of Comics books from MarvelAPI. After getting the data from the API. MY GOAL was to check these Comics book to see if they have image or not. If they do not have image, I would like to go onto the next comic book and look for the one that has an image then add it to the empty variable up until three comics. Here is my sample of code that I have been working on so far. First, I created an empty variable, and second variable with the data from the API. Then I declare the count to be at 0 to start off. Then I run a for loop through the entire data that was coming back from the API. Then an if statement to check the condition for the image path. This is where thing get crazy because if I push the second variable to the first; it will just essentially the entire data from the api. What did I do wrong or what am I missing from here. Please someone help a fellow beginner.
var comicsWithImage = []
var fullListComics = comicsData.data.results;
var count = 0;
for(var i = 0; i < fullListComics.length; i++){
if(count == 3){
break
}
if(comicsData.data.results[0].thumbnail.path !== 'image_not_available'){
comicsWithImage.push(fullListComics)
count++
console.log(comicsWithImage)
}
}
Aucun commentaire:
Enregistrer un commentaire