What is the principle of JavaScript paging algorithm?

clipboard.png
the code that implements the paging algorithm for the picture above is a little confusing.
1. Isn"t the page declared by const a constant? Doesn"t page change every time forEach iterates through it? But why did not report wrong, is not my understanding wrong, or my knowledge point blind spot?
2. The overall algorithm is a bit confusing. Please give us some advice. Thank you
Code:
pages () {

const=[]
this.iconList.forEach((item,index) => {
    const page =Math.floor(index/8)
    if(!pages[page]){
    pages[page]=[]
    }
    pages[page].push(item)
})
return pages

}

May.05,2021

1: const in the scope of forEach does not involve modification

2: index input is 0 12. His side of the 8 processing 0-8 is processed to 0
the final format should be:

[{
  X :...,
   ...
},{},{}]

the scope of const page traversing each loop is only the current arrow function , and the life cycle of the function ends after execution; therefore, there is no problem of repeated declaration.

the overall logic is very simple, there is no algorithm;

pages(){
    // 
    const pages=[]
    // icon
    this.iconList.forEach((item,index) => {
        // 8;:0-7
        // page;
        const page =Math.floor(index/8)
        // pages;
        if(!pages[page]){
            pages[page]=[]
        }
        // icon;
        pages[page].push(item)
    })
    // icon;
    return pages
}

the scope of your const constant is within the anonymous function of forEach. There is a concept of function call stack. Every time the function is executed, the function is put on the stack, and after execution, the function context is destroyed.
then stores eight pieces of data on a page, eight pieces of data as an array, and if it reaches the critical point, declare an empty array to hold the next eight pieces of data.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5046f-43b79.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5046f-43b79.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?