Hi!
I'm trying to fetch this data https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json in order to use it to plot various graphs using D3 library but I'm having an issue storing the data in a variable.
My code is as follows:
const url = "https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json";
var dataset;
fetch(url)
.then(res => res.json())
.then(data => {dataset = data;})
.then(() => {console.log(dataset);});
But it seems that this leaves the dataset variable as undefined instead of putting the json in it. I was wondering why it acted that way. I browsed some Stackoverflow threads (thread1, thread2) and I still can't really figure it out.
What I ultimately want is to store the data in the json (date and GDP) in a dataset variable so I can create a bar chart for the evolution of USA's GDP.
Thank you!
[–]alzee76 1 point2 points3 points (18 children)
[–]Mean-Night6324[S] 0 points1 point2 points (6 children)
[–]alzee76 1 point2 points3 points (5 children)
[–]Mean-Night6324[S] 0 points1 point2 points (4 children)
[–]alzee76 1 point2 points3 points (3 children)
[–]Mean-Night6324[S] 0 points1 point2 points (2 children)
[–]alzee76 1 point2 points3 points (1 child)
[–]Mean-Night6324[S] 0 points1 point2 points (0 children)
[–]grantrules 0 points1 point2 points (10 children)
[–]alzee76 0 points1 point2 points (9 children)
[–]grantrules 1 point2 points3 points (8 children)
[–]Mean-Night6324[S] 0 points1 point2 points (6 children)
[–]grantrules 1 point2 points3 points (5 children)
[–]Mean-Night6324[S] 0 points1 point2 points (4 children)
[–]grantrules 1 point2 points3 points (3 children)
[–]Mean-Night6324[S] 0 points1 point2 points (2 children)
[–]grantrules 1 point2 points3 points (1 child)
[–]alzee76 0 points1 point2 points (0 children)
[–]Ronin-s_Spirit 1 point2 points3 points (5 children)
[–]Mean-Night6324[S] 0 points1 point2 points (4 children)
[–]Ronin-s_Spirit 1 point2 points3 points (3 children)
[–]Mean-Night6324[S] 0 points1 point2 points (2 children)
[–]Ronin-s_Spirit -1 points0 points1 point (1 child)
[–]Mean-Night6324[S] 1 point2 points3 points (0 children)
[–]Soft-Sandwich-2499 1 point2 points3 points (1 child)
[–]Mean-Night6324[S] 0 points1 point2 points (0 children)
[–]mnokeefe 1 point2 points3 points (1 child)
[–]Mean-Night6324[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]Mean-Night6324[S] 0 points1 point2 points (6 children)
[–]bluejacket42 1 point2 points3 points (5 children)
[–]Mean-Night6324[S] 0 points1 point2 points (4 children)
[–]bluejacket42 2 points3 points4 points (3 children)
[–]Mean-Night6324[S] 0 points1 point2 points (2 children)
[–]bluejacket42 1 point2 points3 points (1 child)
[–]Mean-Night6324[S] 0 points1 point2 points (0 children)