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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter