js給Array數(shù)組增加chunk方法.
Array.prototype.chunk = function(n){
for(var i = 0, temp = [], l = ~~this.length / n; temp.length < l; temp[i++] = this.splice(0, n));
return temp;
}
var array = '173IT技術(shù)網(wǎng)很棒,中國人民很行'.split('')
// to use
array .chunk(2)
array .chunk(3)
更多信息請查看IT技術(shù)專欄