Working on the d3 challenge but this is more a vanilla JS issue. Pen here.
I have pulled JSON data which has more than a I need and defined the dataset to just be the “data” part of the JSON. That much is working. However, when I try to split the data array into two arrays, it doesn’t work.
Working part:
d3.json("https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json").then(function(data){ //console.log(data["data"]);
const dataset = data["data"];
console.log(dataset[0], dataset.length, "got data")
const w = 500;
const h = 100;
Right now I am focused on getting the second entry of each subarray. (This is GDP data, hence my name for the variable.)
Not so working part (0 for 3 approaches:
let gdps = dataset.mep(function(item) {
return item[1];
})
console.log(gdps);
let gdps2 = [];
for(let i = 0; i < dataset.length, i++) {
gdps2[i] = dataset[i][1]
}
console.log(gdps2);
let gdps3 = dataset.forEach(function(item) {
gdps3.append(item[1])})
console.log(gdps3);
I can’t see what I’m doing wrong, and getting no errors in the console or browser.
Thanks!