I would like to enquire some information about looping in javascript. I have an object that looks:
[
{
"pageId": "1",
"menuPos": "Parent",
"mainPageId": "1",
"subMenu": [
{
"pageId": "1",
"menuPos": "Parent and child",
"mainPageId": "1",
"subMenu": [
{
"pageId": "67",
"menuPos": "Child",
"mainPageId": "67"
},
{
"pageId": "68",
"menuPos": "Child and paren",
"mainPageId": "68",
"subMenu": [
{
"pageId": "70",
"menuPos": "Child",
"mainPageId": "70"
},
{
"pageId": "69",
"menuPos": "Child",
"mainPageId": "69"
}
]
}
]
}
]
}
]
I've tried to use "key in array" but using this i can only reach first level of my array. The problem is that i don't know how many levels will be in this array.
I want to assing some information from this array to a new arrays object and send it to the server.
It has to look like this.
[
{
"pageId": "1",
"menuPos": "Parent",
"subMenu": [
{
"pageId": "1",
"menuPos": "Parent and child",
"parentId":1,
"subMenu": [
{
"pageId": "67",
"menuPos": "Child",
"parentId": 1,
},
{
"pageId": "68",
"menuPos": "Parent and child",
"parentId": 1,
"subMenu": [
{
"pageId": "70",
"menuPos": "Child",
"parentId": 68,
},
{
"pageId": "69",
"menuPos": "Child",
"parentId": 68,
}
]
}
]
}
]
}
]