Saturday, December 13, 2025
HomeLanguagesJavascriptCollect.js eachSpread() Method

Collect.js eachSpread() Method

The eachSpread() method is used to iterate over the collection items and pass each nested item value of collection into the given callback function.

Syntax:

collection.eachSpread()

Parameters: The collect() method takes one argument that is converted into the collection and then eachSpread() method is applied on it, which can take element if you apply it on the collection of objects.

Return Value: This method iterates over the collection of items.

Below example illustrate the eachSpread() method in collect.js:

Example 1:

Javascript




const collect = require('collect.js');
  
const collection = collect([
    ['Rakesh', 80],
    ['Shyam', 94],
    ['Sandeep', 75],
    ['Ashok', 88]
]);
  
collection.eachSpread((name, marks) => {
    console.log("Name => " + name 
        + " | Marks => " + marks)
});


Output:

Name => Rakesh | Marks => 80
Name => Shyam | Marks => 94
Name => Sandeep | Marks => 75
Name => Ashok | Marks => 88

Example 2:

Javascript




const collect = require('collect.js');
  
let arr = [
    ['Rahul', 98],
    ['Aditya', 96],
    ['Abhishek', 80],
];
  
// Converting object to collection 
const collection = collect(arr);
  
collection.eachSpread((name, score) => {
    console.log(name, score);
});
  
console.log(collection.eachSpread(
    (name, score) => false)
);


Output:

Rahul 98
Aditya 96
Abhishek 80
Collection {
 items: [ 
   [ 'Rahul', 98 ], 
   [ 'Aditya', 96 ], 
   [ 'Abhishek', 80 ] 
 ]
}
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
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS