I have been trying to read multiple csv file for d3 library following other stack overflow. All csv data will be stored in array results. But checking at results by chrome developer tool, data is stored to result weird way as shown in below image. I can see that data is stored to results array, but I cannot specify elements stored in the array. Can anyone tell me how I can specify elements in this array case? or tell me how to avoid storing data to array this way?
I can see that data is stored in array, but if I try to get element from array ,they return "undefined":

function multicsv(files){
var results=[];
var categories=[];
//var category=[];
var filesLength = (files || []).length;
//console.log(filesLength);
var count=0;
var counter=function(){
return count++
}
for (var i=0 ;i<filesLength;i++){
d3.csv(files[i], function(data){
ix=counter();
data,category=get_category(data,ix);
//console.log(data);
arr=fitstruct(category,data);
//console.log(arr);
//results.push(arr);
results[ix]=arr
//categories.push(category)
categories[ix]=category
});
}
console.log(results);
console.log(results[0]);
};
function get_category(data,ix){
var category=[]
data.forEach(function(d){
if(d.Subcategory=="General"){
d.category=d[""]
category.push(d[""]);
}else if(d.Subcategory!="General"){
d.category=d.Subcategory;
category.push(d.Subcategory);
};
d.electric=+d["Electricity [kWh]"];
d.version=ix;
})
return data,category
};
function fitstruct(list,data){
var electricity=[];
var total=0
for (i=0;i<list.length;i++){
//electricity.push(category[i],data[i]["electric"])
electricity[list[i]]=data[i]["electric"]/1000000
total+=data[i]["electric"]
}
electricity["version"]=data[0]["version"];
electricity["total"]=total/1000000
return electricity
};
console.log(categories);returns[], which means thecategoriesarray is empty. When an array is empty you will receive anundefinedwhen you try to access an element bycategories[0].multicsvfunction there are semicolons missing at the end of two lines which could have unwanted side effects. Always use semicolons :) Beside that avaris missing before declaration ofixvariable.get_categoryyou try to return multiple values from a function. AFAIK this is not possible. Try something like this instead.