After reading a csv file with the following code:
var x="dema.csv";
loadCSV(x);
function loadCSV(file) {
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
var request = new XMLHttpRequest();
} else {
// code for IE6, IE5
var request = new ActiveXObject('Microsoft.XMLHTTP');
}
// load
request.open('GET', file, false);
request.send();
parseCSV(request.responseText);
}
I used the next piece of code to put the data into a dataObject:
function parseCSV(data, dataArray) {
//replace UNIX new lines
data = data.replace(/\r\n/g, "\n");
//replace MAC new lines
data = data.replace(/\r/g, "\n");
//split into rows
var rows = data.split("\n");
// loop through all rows
for (var i = 0; i < rows.length; i++) {
// this line helps to skip empty rows
if (rows[i]) {
// our columns are separated by comma
var column = rows[i].split(",");
var date=column[0];
var value = column[4];
var dataObject = {
date: date,
T4: value
};
dataArray.push(dataObject);
}
}
}
When extracting only the date and T4 columns, I encountered an issue. I am looking for a way to process the data, potentially using loops to validate certain conditions (e.g., ensuring that T4 does not exceed 700 over a 30-second period). Should I stick with using a dataObject or switch to a 2D array? What is the best tool for accessing cell contents in this scenario?