Skip to content

Instantly share code, notes, and snippets.

@AlexLo33
Created November 7, 2018 08:30
Show Gist options
  • Save AlexLo33/e67af763acb0a71a875db915d8dbea25 to your computer and use it in GitHub Desktop.
Save AlexLo33/e67af763acb0a71a875db915d8dbea25 to your computer and use it in GitHub Desktop.
onChange(files){
const f = files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
const data = e.target.result;
const lines = data.split("\n");
const headers = lines[0].split(",");
lines.shift();
const result = [];
for (let i = 0; i < lines.length; i++) {
const lineData = lines[i].split(",");
const obj = {};
for (let j = 0; j < headers.length; j++) {
obj[headers[j]] = lineData[j];
}
result.push(obj);
}
console.log(result);
};
})(f);
reader.readAsText(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment