So, I have been trying to wrap my head around d3.js and cannot for the life of me figure out a way to splice an array. In the code below, i am importing a csv file (which has >30000 rows) and then trying to subset it to the first 40 values by splicing the array. While the command works in the console tab (i.e. data.splice(0,40)), it doesn't work within the script. What am i doing wrong?
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-array.v1.min.js"></script>
<script>
d3.csv("for_musp.csv", function(data2) {
data = data2.map(function(d) { return +d["label"] ; });
});
var newData = data.splice(0,40);
};
</script>