[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/flow](../../README) / [index](../README) / paginate

# Function: paginate()

> **paginate**\<`T`\>(`items`, `page?`, `perPage?`): [`Paginator`](../interfaces/Paginator)\<`T`\>

Defined in: [flow/src/pagination.ts:106](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/pagination.ts#L106)

Paginate an in-memory array — the array counterpart to the ORM's
`.paginate(perPage, page)`. Use this for filtered/derived data you already
hold in memory (e.g. inside `render()` or `onMount()`); for database queries
prefer the query builder's paginator.

`page` is clamped into `[1, lastPage]` and `perPage` is floored to at least 1,
so out-of-range input never throws.

## Type Parameters

### T

`T`

Element type of `items`.

## Parameters

### items

`T`[]

The full, already-in-memory collection to page over.

### page?

`number` = `1`

1-based page to return (clamped; default `1`).

### perPage?

`number` = `15`

Items per page (floored to >= 1; default `15`).

## Returns

[`Paginator`](../interfaces/Paginator)\<`T`\>

A [Paginator](../interfaces/Paginator) for the requested page.

## Example

```ts
const results = posts.filter((p) => p.published);
const page = paginate(results, this.page, 10);
for (const post of page.data) { ... }
```
