> For the complete documentation index, see [llms.txt](https://tedirghazali.gitbook.io/algajs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tedirghazali.gitbook.io/algajs/array/paginate.md).

# $.array.paginate

#### Paginate the array

You may want to create a pagination or to split the data into many pages for your table, post or other components. Here you need to use paginate helper to show only entries by the page limit (I mean the limit of entries per page) and by the current page active, this method will produce a new array.

```
$.array.paginate(fromArray, pageActive, limitPerPage)

// Example:
const fromArray = [
  { id: 1, name: 'Hanbal Tedir', office: 'Jakarta', age: 30 },
  { id: 2, name: 'Dawoud Tedir', office: 'Medan', age: 27 },
  { id: 3, name: 'Harist Tedir', office: 'Sigli', age: 15 },
  { id: 4, name: 'Tedir Ghazali', office: 'Banda Aceh', age: 29 },
  { id: 5, name: 'Hanbal Usman', office: 'Langsa', age: 27 },
  { id: 6, name: 'Dawoud Usman', office: 'Pidie', age: 25 },
  { id: 7, name: 'Harist Usman', office: 'Samarinda', age: 18 },
  { id: 8, name: 'Ghazali Usman', office: 'Balikpapan', age: 45 },
  { id: 9, name: 'Bukhari Usman', office: 'Makassar', age: 44 },
  { id: 10, name: 'Boyhaki Usman', office: 'Jaya Pura', age: 35 },
  { id: 11, name: 'Zulkifli Usman', office: 'Manado', age: 56 },
  { id: 12, name: 'Teuku Usman', office: 'Ternate', age: 58 }
]
$.array.paginate(fromArray, 3, 5)
//=> [
// { id: 11, name: 'Zulkifli Usman', office: 'Manado', age: 56 },
// { id: 12, name: 'Teuku Usman', office: 'Ternate', age: 58 }
//]
```

#### Pagination numbers or items

Creating pagination with javascript from scratch might be a bit tricky to do, so I provide a pagination helper to just solve that problem, this pagination helper will render a new array with pagination numbers in it, by using this method you guys can build a complete pagination through iteration.

```
$.array.pagination(totalPages, pageActive, positionEllipsis)

// Example:
$.array.pagination(12, 5, 2)
//=> ['...', 3, 4, 5, 6, 7, '...']
```

#### Get total pages from array

Before creating a pagination, we need to know the total pages of data, items, entries or record from the array, this is why we provide a helper for just generating a number of total pages.

```
$.array.pages(fromArray, limitPerPage)

// Example:
$.array.pages(values, 5)
//=> 3
```

#### Showing the information of pagination and entries per page

You may want to get the information of the current entries from the current page, here we provide pageInfo and will return an object with properties such as the entries that start from the beginning of page in a number, that end to the last entries of that page in a number and the total entries in a number.&#x20;

```
$.array.pageInfo(fromArray, pageActive, limitPerPage)

// Example:
$.array.pageInfo(values, 3, 5)
//=> { from: 11, to: 12, of: 12 }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tedirghazali.gitbook.io/algajs/array/paginate.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
