Snippets Collections
const paginate = (array) => {
  const itemsPerPage = 10;
  const numberOfPages = Math.ceil( array.length / itemsPerPage);

  // need to create an array of arrays [[10], [20], [30]] etc
  return Array.from({ length: numberOfPages }, (_, pageIndex) => {
    const startIndex = pageIndex * itemsPerPage;
    return array.slice(startIndex, startIndex + itemsPerPage);
  });

}

export default paginate
star

Mon Aug 28 2023 21:14:16 GMT+0000 (Coordinated Universal Time)

#javascript #pagination #array #of #arrays
star

Fri Aug 25 2023 10:45:21 GMT+0000 (Coordinated Universal Time) https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

##size #sizes #of #various

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension