A method about the Array group page
/*
'arr' is the array to be paged. 'page' is current page number,default value is 1.
'limit' is the number of entries per page,default value is 50.
return three parameters. 'total' is the length of the array.
'pages' is the total number of pages in the array.
'list' is the data of each page you want.
*/
export const arrayPage = (arr, page = 1, limit = 50) => {
const floor = (page - 1) * limit;
const ceil = arr.length > page * limit ? page * limit : arr.length;
const list = arr.length > floor ? arr.slice(floor, ceil) : [];
return {
total: arr.length,
pages: Math.ceil(arr.length / limit),
list,
}
};