To delete all rows in an HTML table with JavaScript, we use the remove
method.
For instance, we write
document.querySelectorAll("table tbody tr").forEach((e) => {
e.remove();
});
to select all tr elements with querySelectorAll
.
Then we call forEach
with a callback to call remove
to remove each tr element.