Hey folks, I’m wiring up a tiny client-side pagination helper for a search results panel, and I’m trying to keep it simple without duplicating items or dropping one when the page size changes.
function getPage(items, page, pageSize) {
const start = page * pageSize;
const end = start + pageSize;
return items.slice(start, end);
}
const items = ["a", "b", "c", "d", "e", "f", "g"];
console.log(getPage(items, 1, 3));
console.log(getPage(items, 2, 2));
Why does this kind of page math feel fine at first but then skip an item across views, and what index logic should I use if page numbers in my UI are meant to start at 1?
Yoshiii