My goal is to read in data from a CSV file, transform it using the map function, and then return the new_mapped data "container".
Since I do not see a way that I can simply return container, I defined a variable "fin_container" outside of the then function so that I could set "fin_container" to "container" within the then function. This way I can return fin_container, which is essentially a copy of "container."
Instead, fin_container never changes. The problem I am having is when I attempt to set "container" to "fin_container", "fin_container" outside of then does not mutate/change - or recognize the reassignment made in the then().
(1) What have I done wrong? (2) Is there an alternative to accomplish what I am trying to accomplish?
var fin_container;
var us_sp_data = d3.csv("theatened.csv");
var transformation = us_sp_data.then(function(d)
{
var container = d.map(
function(d)
{
return {s_n: d["Scientific Name"]}
});
var fin_container = container;
});
console.log("fin",fin_container);
return fin_container;