I am trying to write a Javascript function that takes an array
, page_size
and page_number
as parameters and returns an array that mimics paginated results:
paginate: function (array, page_size, page_number) {
return result;
}
so for example when:
array = [1, 2, 3, 4, 5],
page size = 2,
page_number = 2,
the function should return: [3, 4]
.
Any ideas would be appreciated.
[3, 4]
represent in relation to all the other variables? It's kind of key that you explain that explicitly – StudioTimeArray.slice
->array.slice((page_number - 1) * page_size, page_size)
(something like that should work) – casraf[1, 2]
,[3, 4]
and[5]
. Page number 2 in this scenario will be[3, 4]
. – SalmaFG