I've taken influence from this post to store CSV files in individual arrays, and it works. I'm looking to add about 8 more arrays that each hold the contents of a CSV file.
But how can I merge these arrays into one array of objects? Having an array of objects is critical for my subsequent application of these arrays. What I have so far is below, but I'm not sure if it is correct or not?
Any help would be appreciated.
var dataCSV;
var dataCSV2;
var collection = {dataCSV, dataCSV2};
d3.csv("data/csv1.csv", function(data) {
data.forEach(function(d) {
d.word = d.word;
d.frequency = +d.frequency;
})
dataCSV = data;
console.log(dataCSV);
});
d3.csv("data/csv2.csv", function(data) {
data.forEach(function(d) {
d.word = d.word;
d.frequency = +d.frequency;
})
dataCSV2 = data;
console.log(dataCSV2);
});
function merge(data1, data2) {
collection = {data1, data2};
console.log(collection);
}
merge(dataCSV, dataCSV2);
Ideally, I'd like the output of collection to be:
collection {
dataCSV {
word: ..., frequency: ...,
word: ..., frequency: ...
},
dataCSV2 {
word: ..., frequency: ...,
word: ..., frequency: ...
}
}