Created
September 17, 2024 13:02
-
-
Save pdaug/af804ea9cd3a0451d2d9eb9445f44014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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