I'm trying to create a new array from the obj values that follow the same length and order as the nested array of objects. I've tried creating nested for loops that would automate the process to do so but haven't had any luck. I have a hardcoded example at the bottom that breaks down what I'm trying to achieve.
The value newArr needs to be
[
[
[0,1],
[2]
],
[
[3],
[4]
],
[
[5],
[6,7,8]
],
[
[9,10,11],
[12,13,14]
],
[
[15,16,17],
]
]
The array of objects newArr will be modeled from
var obj = [
[
[{foo:0},{foo:1}],
[{foo:2}]
],
[
[{foo:3}],
[{foo:4}]
],
[
[{foo:5}],
[{foo:6},{foo:7},{foo:8}]
],
[
[{foo:9},{foo:10},{foo:11}],
[{foo:12},{foo:13},{foo:14}]
],
[
[{foo:15},{foo:16},{foo:17}],
]
]
The array of numbers keeping track of the nested array of objects position
var nums = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
Stores nums in the order and length of each array of objects
var newArr = []
Creates nth amount of secondary parent arrays equivalent to obj length
for(var i=0;i<obj.length;i++) {
newArr.push([])
}
Hardcoded example of newArr pushing numbers from the nums array
Here I'm splicing num with 0 as the first parameter and the lengths of the first two nested arrays from obj
The main goal is not to hardcode the values to create the new array but to create some kind of for loop that would handle it
newArr[0].push([nums.splice(0,2)])
newArr[0].push([nums.splice(0,1)])