方法一:
var result = [];
var data = [
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
{name:'chen',age:'25'},
]
for(var i=0;i<data.length;i+=3){
result.push(data.slice(i,i+3));
}
//[
//[{name:'chen',age:'25'},{name:'chen',age:'25'},{name:'chen',age:'25'}],
//[{name:'chen',age:'25'},{name:'chen',age:'25'},{name:'chen',age:'25'}],
//[{name:'chen',age:'25'},{name:'chen',age:'25'},{name:'chen',age:'25'}],
//[{name:'chen',age:'25'}],
//]
方法二:
var spArray = function(N,Q){
var R = [],F;
for (F = 0;F < Q.length;) {
R.push(Q.slice(F,F += N))
}
return R
}
var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14];
console.log(spArray(5,arr))//[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14]]
————————————————
版权声明:本文为CSDN博主「The wind is blowing」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43156398/article/details/90715915