I need to analyze data using JS, and display it on an HTML page. The data source is a CSV file, so I used the following code for extracting the data:
var data;
$(document).ready(function(){
$("#csv-file").change(handleFileSelect);
});
function handleFileSelect(evt) {
var file = evt.target.files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
data = results;
}
});
}
When I press F12 in Chrome - with breakpoint on the row following "data=results", I can see that "data" is an array with 50 objects - each contains a whole row from the CSV in a Key-Value format, where the "Key" is the header from the file and the "value" is the content.
The problem is that I can't access the data. For example, I tried writing:
var x = document.getElementById("one");
x.innerHTML=data[1].Date;
but there's an error on the second line... So - Does anyone can help me with how can I get access to the "data" variable? in which part of the code I need to insert the lines that tries to get the data?