var lines = [];
document.getElementById("fileInput").addEventListener("change", readSingleFile, true);
console.log(lines.length);
function readSingleFile(evt) {
var f = evt.target.files[0];
if (f) {
var read = new FileReader();
read.onload = function(evt) {
var contents = evt.target.result;
var ct = read.result;
var lines = ct.split('\n');
}
read.readAsText(f);
}
}
...
<body>
<input type="file" id = "fileInput">
<script src="index.js"></script>
</body>
...
I want to read the content of the file to array lines. The console.log(lines.length) returns 0(which I think is because variables in js have function scope). How can I access the values in array 'lines' outside of the function. Any help would be much appreciated!!