Javascript Array chunk(chunkSize)
Array.prototype.chunk = function(chunkSize) { var array = this; return [].concat.apply([], array.map(function(elem,i) { return i%chunkSize ? [] : [array.slice(i,i+chunkSize)]; })//from w ww . j a va 2 s .c o m ); };
// Splits an array in multiple subarrays with arbitrary length Array.prototype.chunk = function(chunkSize) { var R = [];//ww w. jav a 2 s. c o m for (var i=0; i<this.length; i+=chunkSize) R.push(this.slice(i,i+chunkSize)); return R; }
Array.prototype.chunk = function chunk(chunkSize) { var array=this; return [].concat.apply([], array.map(function(elem,i) { return i%chunkSize ? [] : [array.slice(i,i+chunkSize)]; })//from www. j ava 2s. c o m ); };
/* eslint-disable no-extend-native */ Array.prototype.chunk = function (n) { if (!this.length) { return []//from www.j ava 2 s. c om } return [ this.slice(0, n) ].concat(this.slice(n).chunk(n)) }
// Chunk the underlying array. Array.prototype.chunk = function(size) { var chunks = []; for (key = 0; key < this.length; key += size) { chunks.push(this.slice(key, key+size)); }//from w w w .j a v a 2 s. co m return chunks; } // Transform the underlying array to dynamic options. Array.prototype.options = function(textKey, valueKey) { var options = []; options = this.map(function(item) { return { text: item[textKey], value: item[valueKey] } }); return options; }