Question : js split array into smaller arrays
Answered by : ever-dev
Array.prototype.chunk = function(n) { if (!this.length) { return []; } return [this.slice(0, n)].concat(this.slice(n).chunk(n));
};
console.log([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].chunk(5));
Source : | Last Update : Thu, 05 Nov 20
Question : split array into chunks javascript
Answered by : friendly-frog-tqciuyft6zd3
Array.prototype.chunk = function(size) { let result = []; while(this.length) { result.push(this.splice(0, size)); } return result;
}
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(arr.chunk(2));
Source : https://stackoverflow.com/questions/8495687/split-array-into-chunks | Last Update : Wed, 26 Aug 20