Is it possible to loop through this nested object, when you don't know how many views ("A", "B", "C"...) this object has? I use currently a alphabetic index, but I heard now the "view layer" can also have different names, so I cant use my current idea, I have to loop through this object without knowing the names of "A", "B", "C" layer. Is there a way?
My current code
loopThroughObject()
{
let alphabet = ["A", "B", "C"];
let index = 0;
this.all_tables.views.forEach(views => {
views[alphabet[index]].forEach(view => {
view.positionen.forEach(position=> {
alert( position.field1);
});
});
index++;
});
}
Nested JSON Object
all_tables = {
"views":[
{
"A":[
{
"id":"",
"username":"",
"status":"",
"location":"",
"positionen":[
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
}
]
},
{
"id":"",
"username":"",
"status":"",
"location":"",
"positionen":[
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
}
]
}
],
"B":[
{
"id":"",
"username":"",
"status":"",
"location":"",
"positionen":[
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
}
]
},
{
"id":"",
"username":"",
"status":"",
"location":"",
"positionen":[
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
}
]
}
],
"C":[
{
"id":"",
"username":"",
"status":"",
"location":"",
"positionen":[
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
}
]
},
{
"id":"",
"username":"",
"status":"",
"location":"",
"positionen":[
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
},
{
"field1":"",
"field2":"",
"field3":""
}
]
}
]
}
]
}