Skip to content

Instantly share code, notes, and snippets.

@shuhei
Created July 29, 2014 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuhei/2b12ff32d97269b3ef36 to your computer and use it in GitHub Desktop.
Save shuhei/2b12ff32d97269b3ef36 to your computer and use it in GitHub Desktop.
CSV to something
var data = [
['Prefecture', 'A', 'B', 'C'],
['Tokyo', '1', '2', '3'],
['Kanagawa', '4', '5', '6']
];
var labels = data[0];
var dataSet = data.slice(1).reduce(function(acc, row) {
var item = {};
item[labels[0]] = row[0];
item.values = row.slice(1).map(function(value, i) {
return { key: labels[i + 1], value: parseInt(value, 10) };
});
acc.push(item);
return acc;
}, []);
console.log(dataSet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment