Skip to content

Instantly share code, notes, and snippets.

@neilcamm
Last active February 12, 2018 18:45
Show Gist options
  • Select an option

  • Save neilcamm/43e612045dea396f0dda42ff217f472d to your computer and use it in GitHub Desktop.

Select an option

Save neilcamm/43e612045dea396f0dda42ff217f472d to your computer and use it in GitHub Desktop.
PHP's array_chunk in JavaScript
var array_chunk = function(array, size) {
var output = [],
i = 0,
n = 0;
for(item in array) {
if(i >= size) {
i = 0;
n++;
}
if(!output[n] || output[n] == 'undefined') {
output[n] = [];
}
output[n][i] = array[item];
i++;
}
return output;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment