0

i have this trouble, i've defined a poke object and i try to clone to this an object thats give me this link https://pokeapi.co/api/v2/pokemon/1/ but i only get a promise fullfiled with the object i search for, no the object itself in the poke object. Here's the code:

let poke = fetch(url).then(response => response.json()).then(data => JSON.parse(JSON.stringify(data)));
console.log(poke);

1 Answers1

0

Add await before, smth like

async () => {
  let poke = await fetch(url).then(response => response.json()).then(data => JSON.parse(JSON.stringify(data)));
  console.log(poke);
}

fetch is async, so you need to wait response, via await or then

  fetch(url).then(response => response.json()).then(data => JSON.parse(JSON.stringify(data))).then(data => {console.log(data)});
A Ralkov
  • 1,046
  • 10
  • 19