Thursday, October 16, 2025
HomeLanguagesJavascriptCollect.js | all() Method

Collect.js | all() Method

The all() method is used to return the underlying array or object represented by the collection. The JavaScript array is first transformed into a collection and then the function is applied to the collection.

Syntax: 

collect(array).all()

Parameters: The method does not accept any parameter.

Return Value: Returns an array or object.

Below examples illustrate the all() method in JavaScript:

Example 1: Here collect = require(‘collect.js’) is used to import the collect.js library into the file.

Javascript




const collect = require('collect.js');
   
let arr = [1, 2, 3]
   
// Convert array into collection
const collection = collect(arr);
   
// Returning the array
let newObject =  collection.all();
   
console.log("Result : ", newObject);


Output:

Result : [1, 2, 3]

Example 2:

Javascript




const collect = require('collect.js');
   
let obj = { first : "neveropen",
        second : "Collect.js"};
   
// Convert object into collection
const collection = collect(obj);
   
// Returning the object
let newObject =  collection.all();
   
console.log("Result : ", newObject);


Output:

Result :  { first: 'neveropen', second: 'Collect.js' }

Reference: https://collect.js.org/api/all.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!
Previous article
Next article
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS