const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
const size = 3;
const groups = items.reduce((a, c, i, s) => i % size === 0 ? [...a, s.slice(i, i + size)] : a, []);
// [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11]]
-
Notifications
You must be signed in to change notification settings - Fork 0
TomasHubelbauer/js-array-groups
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
JavaScript Split Array Into Groups of the Same Size