JS数组分页,页数,每页条数,数组

JS数组分页

function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}

演示代码

function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}


var  a=[1,2,3,4,5,6,7,8,9,10]
pagination(3,3,a)
//[7, 8, 9]
posted @ 2022-05-02 09:02  风意不止  阅读(1066)  评论(0编辑  收藏  举报