Takes the first array in the array and uses that to set the properties of an array-object.
var _ = require("underscore");
function csvToObject(data){
var header = data.shift();
return _.map(data, function(row){
var temp = {};
_.each(row, function(cell, key){
temp[header[key]] = cell;
});
return temp;
});
}
I created a non-underscore dep version
function csvToObject2(data) {
var header = data.shift();
var alpha = [];
for (var i = 0; i < data.length; i++) {
var beta = {};
for (var j = 0; j < data[i].length; j++) {
beta[header[j]] = data[i][j];
}
alpha.push(beta);
}
return alpha;
};
They both performed the same in jsPerf. Thoughts?