function group(array, chunk) { var stack = []; for(var i = 0, len = array.length; i < len; i += chunk) { stack.push(array.slice(i, i + chunk)); } return stack; } alert(JSON.stringify(group([1,2,3,4,5,6,7], 3)));