Javascript Array chunk(chunk = 2)

Description

Javascript Array chunk(chunk = 2)



Array.prototype.chunk = function (chunk = 2) {
    var i, j, temparray = [];
    for (i = 0, j = this.length; i < j; i += chunk) {
        temparray.push(this.slice(i, i + chunk));
    }/*  w  ww .j  av a2  s  . c o  m*/
    return temparray
}



PreviousNext

Related