Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@CodeMaxter
Forked from mohammad-haji/chunk-array.js
Created May 18, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeMaxter/d3c15a7bd211da118ef72368915133b5 to your computer and use it in GitHub Desktop.
Save CodeMaxter/d3c15a7bd211da118ef72368915133b5 to your computer and use it in GitHub Desktop.
/**
* chunk array into specific chunks :)
* @param arr
* @param len
* @returns {Array}
*/
function chunkArray(arr, len) {
if (!Array.isArray(arr)) return [];
let chunks = [],
i = 0,
arrayLen = arr.length;
while (i < n) {
chunks.push(arr.slice(i, i += len));
}
return chunks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment