https://github.com/writetome51/array-get-page
Javascript function that paginates an array.
https://github.com/writetome51/array-get-page
Last synced: 6 months ago
JSON representation
Javascript function that paginates an array.
- Host: GitHub
- URL: https://github.com/writetome51/array-get-page
- Owner: writetome51
- License: mit
- Created: 2020-07-07T02:25:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-30T19:22:11.000Z (over 4 years ago)
- Last Synced: 2025-02-03T17:59:24.897Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getPage\(
pageNumber,
itemsPerPage,
array: T[]
): T[]
Paginates the data in `array`.
`array` is never modified.
## Examples
```js
let arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
console.log(getPage(1, 5, arr));
// --> [1,2,3,4,5]
console.log(getPage(2, 5, arr));
// --> [6,7,8,9,10]
console.log(getPage(1, 7, arr));
// --> [1,2,3,4,5,6,7]
console.log(getPage(3, 7, arr));
// --> [15,16,17,18,19,20]
console.log(getPage(4, 7, arr));
// --> 'Error: The requested page does not exist'
console.log(getPage(1, 19, arr));
// --> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
console.log(getPage(2, 19, arr));
// --> [20]
```
## Installation
`npm i @writetome51/array-get-page`
## Loading
```js
import { getPage } from '@writetome51/array-get-page';
```
## License
[MIT](https://choosealicense.com/licenses/mit/)