When I console.log my array it remains empty, so I am failing to push the element into the array with my code. I can do it outside of a function, but do not know what I am doing wrong here with the promises. I am new to promises. Thanks for any tips:
function fetchApiData(num) {
let arr = [];
for(let i = 0; i < num; i++) {
fetch('https://dog.ceo/api/breeds/image/random')
.then(response => response.json())
.then(responseJson => console.log(responseJson.message))
.then(responseJson => arr.push(responseJson.message));
console.log(arr);
}
console.log(arr);
// how do I change console.log to push value into an array?
}