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

Collect.js mapSpread() Method

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

Syntax:

collect(array).mapSpread(callback)

Parameters: The collect() method takes one argument that is converted into the collection and then mapSpread() method is applied on it. The mapSpread() method holds the callback function as parameter.

Return Value: This method returns collection items according to given callback function.

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

Example 1:

Javascript




const collect = require('collect.js');
  
const arr = ['a', 'b', 'c'];
  
const collection = collect(arr);
  
const sequence = collection.mapSpread(
    element => element.toUpperCase());
  
console.log(sequence.all());


Output:

[ 'A', 'B', 'C' ]

Example 2:

Javascript




const collect = require('collect.js');
  
const arr = [2, 4, 5, 6, 7, 8, 10, 11];
  
const collection = collect(arr);
  
const sequence = collection.mapSpread(
    element => element % 2 == 0);
  
console.log(sequence.all());


Output:

[
  true, false,
  true, false,
  true, false,
  true, false
]
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