Monday, June 15, 2026
HomeLanguagesJavascriptCollect.js | forPage() Function

Collect.js | forPage() Function

The forPage() function is used to return the value which is present at a particular page, this function take the page number as an argument and then returns the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.

Syntax: 

data.forPage(x,y)

Parameters: This function accept two parameter as mentioned above and described below :

  • x: This parameter holds the page number.
  • y: This parameter holds the number of items to show per page.

Return Value:  Returns a new collection.
 

Below examples illustrate the forPage() function in collect.js
Example 1: Here in this example, we take a collection and then using the forPage() function we display the value from the page given as argument, and return the value

Javascript




// It is used to import collect.js library
const collect = require('collect.js');
 
const collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9]);
const Page= collection.forPage(2, 5);
console.log(Page.all());


Output:

[ 6, 7, 8, 9 ]

Example 2:

Javascript




// It is used to import collect.js library
const collect = require('collect.js');
 
const collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9]);
 
const Page= collection.forPage(4, 2);
console.log(Page.all());


Output:

[ 7, 8 ]

Reference: https://collect.js.org/api/forPage.html

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS