I'm getting a .csv like this:
animal, branco
animal, preto
inseto, branco
inseto, preto
animal, cinza
I want to be able to use this mass of data this way:
// obj = { animal : [branco, preto, cinza] , inseto:[branco, preto]}
BUT that I can access this information with numeric index (something like this)
// obj[0] => animal : [branco, preto, cinza]
// obj[1] => inseto :[branco, preto]
// obj[0[2]] => cinza
// obj[1[0]] => branco
I'm currently using a forEach like this:
const csvFile = fs.readFileSync(__dirname + '/in/classification.csv', 'utf8');
let data = csvFile.split('\n');
let final = {};
csv.forEach(function (row) {
row = row.split(',');
if (!final[row[0]]) {
final[row[0]] = [];
}
final[row[0]].push(row[1]);
});
// output: { animal : [branco, preto, cinza] , inseto:[branco, preto]}
but I can not access the properties using numeric index. is there a better way to do this?