I'm trying to extract data from an online .csv file and when I do my function returns a promise. What I would like to do is take data from the promise and append (or push) it to an array so that I can use it in my visualization.
the issue I'm facing is dataFinal
is empty and someData
only contains values inside the .then()
function.
Any tips on how to get data into my arrays would be much appreciated!
Here's what I currently have:
async function getData() {
const nytdata = await d3.csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv")
return nytdata
}
let nytdata = getData();
var someData = [];
var datafFinal = someData.then(function(result) {
for (var i = 0; i < data.length; i++) {
someData.push({
date: data[i]["date"],
value: data[i]["cases"],
group: data[i]["date"].getMonth()
});
}
return someData
});
console.log(datafFinal)