Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
const { length } = array;
const maxLength = 4;
const iteratorCount = length / maxLength;
let twoDimensionArray = [];
for (let i = 0; i < iteratorCount; i++) {
twoDimensionArray = [
...twoDimensionArray,
array.slice(i * maxLength, (i + 1) * maxLength),
];
}
console.log(array);
console.log(twoDimensionArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment