I have a simple csv file. Sample data is given below (sample.csv).
date,team_1,team_2
2019-06-12,AUS,PAK
2019-06-13,IND,NZ
I want the above to be displayed as a table in a HTML page, such that new rows will automatically add to the table as and when a new record is added to the csv file.
Can someone please help me with a very simple solution?
EDIT: Based on answer to this question, I have written (copied) the following piece of code, but other than the first line, it does not show anything.
function createTable() {
var array = [
["date","team_1","team_2"],
["2019-06-12","AUS","PAK"],
["2019-06-13","IND","NZ"]
];
var content = "";
array.forEach(function(row) {
content += "<tr>";
row.forEach(function(cell) {
content += "<td>" + cell + "</td>";
});
content += "</tr>";
});
document.getElementById("t1").innerHTML = content;
}
createTable()
<table id="t1"> </table>
createTable()function read a CSV file instead of a hardcoded array, and (2) How do I invoke that function from<table>so that the rows and cells are populated based on thecontent.\nand then split on comma