[js] Divide the 8 pieces of data in the array into 4 groups

8 pieces of data[8 pieces of data]===》[[2 pieces of data],[2 pieces of data],[2 pieces of data],[2 pieces of data]]

const goodsList=[
    {
        "id": "4026198",
        "name": "经典格子元素,男童加绒格子衬衫",
    },
    {
        "id": "4020262",
        "name": "休闲潮流运动男士胸包",
    },
    {
        "id": "4027473",
        "name": "新款LOGO印花时尚学步叫叫鞋",
    },
    {
        "id": "4023638",
        "name": "抓绒保暖,毛毛虫儿童运动鞋26-30",
    },
    {
        "id": "4005110",
        "name": "人手必备,儿童轻薄透气防蚊裤73-140cm",
    },
    {
        "id": "3995192",
        "name": "毛茸茸小熊出没,儿童羊羔绒背心73-90cm",
    },
    {
        "id": "4004565",
        "name": "会降温的儿童防蚊裤110-160cm",
    },
    {
        "id": "4011740",
        "name": "抑菌保鲜黑科技泰国可微波冷冻食物保鲜盒",
    },
]
const sliders=[]
const pageSize=2 //每一页几条数据
const pageCount=Math.ceil(goodsList.length/pageSize)//一共几页(几组)
for(let i =0;i<pageCount;i++){
    sliders.push(goodsList.slice(pageSize*i,pageSize*(i+1)))
}
console.log(sliders);

Guess you like

Origin blog.csdn.net/weixin_51290060/article/details/129668830