Skip to content
Subhajit Sahu edited this page Mar 13, 2020 · 22 revisions

Splits array into chunks of given size.

array.chunk(x, [n]);
// x: an array
// n: chunk size (1)
// --> chunks
const array = require('extra-array');

array.chunk([1, 2, 3, 4], 2);
// [ [ 1, 2 ], [ 3, 4 ] ]

array.chunk([1, 2, 3, 4, 5], 2);
// [ [ 1, 2 ], [ 3, 4 ], [ 5 ] ]

array.chunk([1, 2, 3, 4, 5], 3);
// [ [ 1, 2, 3 ], [ 4, 5 ] ]

references

Clone this wiki locally