JSFiddle - React, Tailwind, and code Playground

HTML

<table id="sample_table">
  <tr>
   <td>1</td>
   <td><input type="text" size="5" id="in2" name="txt2" value="0"/></td>
   <td><input type="text" size="5" id="in3" name="txt3" value="0"/></td>
   <td><input type="text" size="5" id="in4" name="txt4" value="0"/></td>
 </tr>

<button type="button" onclick="exportF('myFile')">Export</button>

JavaScript

function exportF(filename) {
    var csv = [];
    var rows = document.getElementById('sample_table').querySelectorAll("table tr");

    for (var i = 0; i < rows.length; i++) {

        var row = [], cols = rows[i].querySelectorAll("td, th");
    
        for (var j = 0; j < cols.length; j++){
						//console.log(cols[j])
            row.push(cols[j].querySelectorAll('input').value);
        }
            
        csv.push(row.join(","));

}

// Download CSV file not posted here
console.log(csv.join("\n"), filename);
}