I'm able to read a file line by line but I do not know how to split each lines using the tab delimited. here my code. Need some help on this issue
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sum of a Column in JavaScript</title>
</head>
<input type="file" name="file" id="file">
<script type="text/javascript">
document.getElementById('file').onchange = function(){
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(progressEvent){
// Entire file
console.log(this.result);
// By lines
var lines = this.result.split('\n');
for(var line = 0; line < lines.length; line++){
// By tabs
var tabs = lines[line].split('\\t');
for(var tab = 0; tab < tabs.length; tab++){
alert(tabs[tab]);
}
}
};
reader.readAsText(file);
};
</script>
I found this useful, and replaced the for ... loops with the js .map() function. Also, I load data into arrays:
Here is how I converted a tab delimited file to a tree format in Node