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#']]]

… [Trackback]
[…] Find More Information here to that Topic: geeksforgeeks.org/collect-js-split-method-2/ […]
… [Trackback]
[…] Read More Information here on that Topic: geeksforgeeks.org/collect-js-split-method-2/ […]