Skip to content

JavaScript Split Array Into Groups of the Same Size

Notifications You must be signed in to change notification settings

TomasHubelbauer/js-array-groups

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

JavaScript Split Array Into Groups of the Same Size

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

About

JavaScript Split Array Into Groups of the Same Size

Topics

Resources

Stars

Watchers

Forks