0

I've written some code that fetches json data from a url and inside of it, I push it's data into an array. Then I try to console.log the array, and I'm able to extend the brackets to see the json data inside but I'm not able to actually access the data. How could I do this? Here is my code,

let playerList = [];
fetch("https://dog.ceo/api/breeds/image/random")
  .then((response) => response.json())
  .then((data) => {
    playerList.push(data)
  });

console.log(playerList);

Here is what it looks like on the developer console as well

Phil
  • 157,677
  • 23
  • 242
  • 245
  • You can see the reason [here](https://jsfiddle.net/40Lhb753/). –  Jun 21 '21 at 06:58
  • how could I fix this? – qwqwqwererer Jun 21 '21 at 07:05
  • 1
    Read the the duplicate in the link and [How to return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) –  Jun 21 '21 at 07:06

0 Answers0