Last active
February 12, 2018 18:45
-
-
Save neilcamm/43e612045dea396f0dda42ff217f472d to your computer and use it in GitHub Desktop.
PHP's array_chunk in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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