Skip to content

Commit ea76889

Browse files
committed
Optimize render function to clear table rows more efficiently
1 parent ac6bc70 commit ea76889

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

debugging/book-library/script.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,15 @@ function Book(bookTitle, author, pages, check) {
4949
this.check = check;
5050
}
5151

52+
5253
function render() {
5354
const table = document.getElementById("display");
5455

55-
// remove all rows except the header
56-
while (table.rows.length > 1) {
57-
table.deleteRow(1);
58-
}
59-
56+
const tbody = table.querySelector('tbody');
57+
tbody.innerHTML = ''; // clears all rows efficiently
58+
6059
myLibrary.forEach((book, i) => {
61-
const row = table.insertRow(1);
60+
const row = tbody.insertRow(); // insert row into tbody
6261

6362
row.insertCell(0).textContent = book.bookTitle;
6463
row.insertCell(1).textContent = book.author;

0 commit comments

Comments
 (0)