So I'm trying to take an object from an API and push that into an array. I put it into a loop so that it will do it multiple times base on a number.
function arrayAPI(){
console.log("arrayAPI ran");
let dogPool = [];
for (i=0; i<dogNumber; i++){
fetch('https://dog.ceo/api/breeds/image/random')
.then(response => responseJSON)
.then(responseJSON => dogPool.push(responseJSON))
.catch(error => alert('error! danger!'));
}
console.log(dogPool);
createTable(dogPool);
However there is something wrong with my fetch code. It goes straight to the .catch
. If I loop it, it will play the error message each time also.
The console.log(dogPool)
tells me that the array is empty.