Google News
logo
Collect.js - Interview Questions
What is the chunk() method in Collect.js?
The chunk() method breaks the collection into multiple, smaller collections of a given size :
Syntax : 
data.chunk(x)

Example : 

const collect = require('collect.js');
const collection = collect([1, 2, 3, 4, 5, 6, 7]);
const x = collection.chunk(5);
console.log(x.all());

Output : 

 [ Collection { items: [ 1, 2, 3, 4, 5 ] },
  Collection { items: [ 6, 7 ] } ]

 

Advertisement