(1)This is the native javascript solution for this issue. It works on most of modern browsers.
function export2csv() {_x000D_
let data = "";_x000D_
const tableData = [];_x000D_
const rows = document.querySelectorAll("table tr");_x000D_
for (const row of rows) {_x000D_
const rowData = [];_x000D_
for (const [index, column] of row.querySelectorAll("th, td").entries()) {_x000D_
// To retain the commas in the "Description" column, we can enclose those fields in quotation marks._x000D_
if ((index + 1) % 3 === 0) {_x000D_
rowData.push('"' + column.innerText + '"');_x000D_
} else {_x000D_
rowData.push(column.innerText);_x000D_
}_x000D_
}_x000D_
tableData.push(rowData.join(","));_x000D_
}_x000D_
data += tableData.join("\n");_x000D_
const a = document.createElement("a");_x000D_
a.href = URL.createObjectURL(new Blob([data], { type: "text/csv" }));_x000D_
a.setAttribute("download", "data.csv");_x000D_
document.body.appendChild(a);_x000D_
a.click();_x000D_
document.body.removeChild(a);_x000D_
}
_x000D_
table {_x000D_
border-collapse: collapse;_x000D_
}_x000D_
_x000D_
td, th {_x000D_
border: 1px solid #aaa;_x000D_
padding: 0.5rem;_x000D_
text-align: left;_x000D_
}_x000D_
_x000D_
td {_x000D_
font-size: 0.875rem;_x000D_
}_x000D_
_x000D_
.btn-group {_x000D_
padding: 1rem 0;_x000D_
}_x000D_
_x000D_
button {_x000D_
background-color: #fff;_x000D_
border: 1px solid #000;_x000D_
margin-top: 0.5rem;_x000D_
border-radius: 3px;_x000D_
padding: 0.5rem 1rem;_x000D_
font-size: 1rem;_x000D_
}_x000D_
_x000D_
button:hover {_x000D_
cursor: pointer;_x000D_
background-color: #000;_x000D_
color: #fff;_x000D_
}
_x000D_
<table>_x000D_
<thead>_x000D_
<tr>_x000D_
<th>Name</th>_x000D_
<th>Author</th>_x000D_
<th>Description</th>_x000D_
</tr>_x000D_
</thead>_x000D_
<tbody>_x000D_
<tr>_x000D_
<td>jQuery</td>_x000D_
<td>John Resig</td>_x000D_
<td>The Write Less, Do More, JavaScript Library.</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>React</td>_x000D_
<td>Jordan Walke</td>_x000D_
<td>React makes it painless to create interactive UIs.</td>_x000D_
</tr>_x000D_
<tr>_x000D_
<td>Vue.js</td>_x000D_
<td>Yuxi You</td>_x000D_
<td>The Progressive JavaScript Framework.</td>_x000D_
</tr>_x000D_
</tbody>_x000D_
</table>_x000D_
_x000D_
<div class="btn-group">_x000D_
<button onclick="export2csv()">csv</button>_x000D_
</div>
_x000D_
(2) If you want a pure javascript library, FileSaver.js could help you save the code snippets for triggering file download. Besides, FileSaver.js will not be responsible for constructing content for exporting. You have to construct the content by yourself in the format you want.