Tuesday, November 18, 2025
HomeLanguagesJavascriptCollect.js split() Method

Collect.js split() Method

The split() method in collect.js is used to break a collection into the given number of groups.

Syntax:

collect(array).split()

Parameters: The collect() method takes one argument that is converted into the collection and then split() method is applied on it.

Return Value: This method returns a collection that is made by splitting the main collection.

Below examples illustrates the split() method in collect.js:

Example 1:

Javascript




// Acquiring collect.js constant
const collect = require('collect.js'); 
     
let arr = [1, 2, 3, 4, 5, 6, 7]; 
     
const collection = collect(arr);
   
const groups = collection.split(4); 
  
let newObject = groups.all();
  
console.log(newObject);


Output:

[[1, 2], [3, 4], [5, 6], [7]]

Example 2:

Javascript




// Acquiring collect.js constant
const collect = require('collect.js'); 
     
let arr = [['c', 'c++'], ['java'], ['python', 'c#']] 
     
const collection = collect(arr);
   
const groups = collection.split(3); 
  
let newObject = groups.all();
  
console.log(newObject);


Output:

[[['c', 'c++']], [['java']], [['python', 'c#']]]
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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32402 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6772 POSTS0 COMMENTS
Nicole Veronica
11921 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11992 POSTS0 COMMENTS
Shaida Kate Naidoo
6899 POSTS0 COMMENTS
Ted Musemwa
7156 POSTS0 COMMENTS
Thapelo Manthata
6853 POSTS0 COMMENTS
Umr Jansen
6845 POSTS0 COMMENTS