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

filter_none

edit
close

play_arrow

link
brightness_4
code

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);

chevron_right


Output:

Result : [1, 2, 3]

Example 2:

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

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

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : Akanksha_Rai

Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.