Recipe: paginate a small in-memory list
Validate pagination inputs, return useful metadata, and know when to switch from a small array example to database cursors.
This dependency-free JavaScript example paginates an already loaded array. It is useful for learning the response contract or displaying a small local collection. It is not an efficient way to paginate a large database: do not load an entire table just to slice it.
The page size is capped and invalid numbers fail explicitly. Empty lists return empty data and no next page. A page beyond the end also returns empty data. Decide whether that behavior suits your interface and document it.

