I am working on one problem when I have one dynamic nested array of similar kind of objects. I have to capture the nested indexes convert it to nested object. Here is the example of two level nested array and I have written simple code to convert it to nested index object. I am looking for iterative or recursive method to handle dynamic nested array and convert to nested similar index object:-
var arr= [
{
"index": "1",
"subRows": [
{
"index": "2",
"subRows": undefined
},
{
"index": "3",
"subRows": undefined
}
]
},
{
"index": "4",
"subRows": [
{
"index": "5",
"subRows": undefined
}
]
}
];
var obj={}
for(var i =0; i<arr.length; i++) {
obj[i]={};
if(arr[i].subRows) {
for(var j=0; j<arr[i].subRows.length; j++) {
obj[i][j] = {};
}
}
}
console.log(obj)