I read a csv file using javascript code and i want to push it into a a 2D Array in order to do some processing
var dataArray = new Array;
function parseCSV(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];
// create object which contains all these items:
var dataObject = {
date: date,
T4: value
};
dataArray.push(dataObject);
}
}
}
}
As a test, i try to read a cell content and display on the web page to verify that i read the file.
<script type="text/javascript">
var x= dataArray[1][4];
document.write(x);
</script>
but it doesn't show anything. Can anyone Help??