let size = 1;
let arr = ["a", "b", "c", "d", "e"]
window.addEventListener("scroll", () => {
const { scrollTop, scrollHeight, clientHeight } = document.documentElement;
if (clientHeight + scrollTop >= scrollHeight - 1) {
size += 1;
console.log("adding");
}
});
let items = arr.slice(0, size);
console.log(items);
This is a dummy array just to showcase the problem. The items
array should receive more items from arr
array as the user reaches the end of the page.
How can I increase a copy of an array using the variable as an endpoint for an array? I'm trying to run this code above but the items
array is not being updated.
This dummy code is a pseudo example of infinite scrolling.