0

I am just trying to access data inside then() method.

var dataset;
fetch ('https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDPdata.json').then (response=>response.json()).then(val=>{

dataset=JSON.stringify(val.data)
});

When i console out it outside then() method it give me this:

undefined;

But when I try to console it out inside , it give me my desired result; I just want to store my desired result in my dataset variable. How?

M A Salman
  • 3,666
  • 2
  • 12
  • 26
Anthony
  • 95
  • 1
  • 7

0 Answers0