js给Array数组增加chunk方法
2015-04-22来源:易贤网

js给Array数组增加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技术网很棒,中国人民很行'.split('')

// to use

array .chunk(2)

array .chunk(3)

更多信息请查看IT技术专栏

2025公考·省考培训课程试听预约报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息