Currently, I am developing a Chrome extension that requires me to retrieve the total number of books available in a library. The current code snippet is functioning correctly, but the issue arises when the page loads only half of the books initially and updates as you scroll down further, causing the array not to update accordingly. Is there a way to automatically refresh the array to reflect these changes?
let list = document.querySelectorAll("ul > li");
let numBooks = [];
for (let i = 0; i < list.length; i++) {
numBooks.push(i + 1);
}
console.log(numBooks);