I have a list object like below
[{a:"0"},{a:"1"},....{a:"39"}]
I want to have a list like the one below.I need a result like the below.
{
"list1":[{a:"0"},{a:"1"},{a:"2"},{a:"3"}],
"list2":[{a:"4"},{a:"5"},{a:"6"},{a:"7"}],
.
.
.
"list10":[{a:"36"},{a:"37"},{a:"38"},{a:"39"}],
}
Thanks for help me.
You can do that using slice()
data...
const arr = [{a:"0"},{a:"1"},{a:"2"},{a:"3"},{a:"4"},{a:"5"},{a:"6"},{a:"7"}];
const arr2 = [];
var i,j;
for (i = 0; i < arr.length; i = i + 4) {
arr2.push(arr.slice(i, i + 4));
}
console.log(arr2);