Cut array into chunks of specified size - Node.js Array

Node.js examples for Array:Array Value

Description

Cut array into chunks of specified size

Demo Code

/* cut array into chunks of specified size */
Array.prototype.chunk = function(s) {
  for(var x, i = 0, c = -1, l = this.length, n = []; i < l; i++)
    (x = i % s) ? n[c][x] = this[i] : n[++c] = [this[i]];
  return n;/* w  w w .  j a v a2  s  . c o  m*/
}

Related Tutorials