把数组按四个一组重新push到一个新的数组
var result = []; var data = [1, 2, 3, 4, 5, 6, 7, 8, 9,10]; var chunk = 4; //每3个分一组 for (var i = 0, j = data.length; i < j; i += chunk) { result.push(data.slice(i, i + chunk)); } console.log(result); console.log('原有数组被分成几组:', result.length); for (var k = 0; k < result.length; k ++) { console.log(result[k]); }