Test
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="CSVObjects.js"></script>
</head>
<body>
<input type="file" id="file"/>
<div id="container"></div>
</body>
</html>
JavaScript
window.onload = function (){
let filHenter = document.getElementById("file");
filHenter.addEventListener("change", grabFileObject)
}
//Task 2 and Task 3
function grabFileObject(event){
//Grabs the uploaded file
let file = event.target.files[0];
let filLeser = new FileReader();
//Reads the file as text and calls anonymous function on load
filLeser.readAsText(file);
filLeser.onload = function (){
//Splits each line
const lines = filLeser.result.split("\n");
//Loop to iterate through each line
for (var i = 0; i < lines.length; i++){
//Splits each line in an element
lines[i] = lines[i].split(",");
//Saves elements to an object.
lines[i] = {Date : lines[i][0],
Type : lines[i][1],
Location : lines[i][2],
Amount : parseFloat(lines[i][3])}
}
console.log(lines);
mainfunction(lines);
}
}
function mainfunction(array){
console.log("Total number of locations: ", totalNumberOfLocations(array));
}
// Task 4.1
function totalNumberOfLocations() {
}