Skip to content

Instantly share code, notes, and snippets.

@pdaug
Created September 17, 2024 13:02
Show Gist options
  • Select an option

  • Save pdaug/af804ea9cd3a0451d2d9eb9445f44014 to your computer and use it in GitHub Desktop.

Select an option

Save pdaug/af804ea9cd3a0451d2d9eb9445f44014 to your computer and use it in GitHub Desktop.
const size = 5;
const list = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21];
const totalPage = Math.ceil(list.length / size);
const paginate = [];
list.map((item, index) => {
const indexPage = Math.trunc(index / size);
if (!paginate?.[indexPage]) {
paginate[indexPage] = [item];
return;
}
paginate[indexPage].push(item);
});
console.log(paginate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment