js数组切片

const arrChunk = (arr,size) =>{
    if(arr.length === 0){
        return [];
    }
    const tempArr = [];
    const chunkLen = Math.ceil(arr.length / size);
    let last = 0;
    for(let i = 0;i<chunkLen;i++){
        if(size * i >= arr.length){
            last = arr.length;
        }else{
            last = size * i + size;
        }
        tempArr.push(arr.slice(size * i,last));
    }
    return tempArr;
}

 

posted @ 2021-05-27 14:36  面包_girl  阅读(1187)  评论(0编辑  收藏  举报
/* 鼠标点击文字特效 */