I am working with a JSON element that contains nested arrays:
json = [
{
"category": "Electronic",
"param": "param1",
"subMenu": [
{
"subCategory": "Audio & Hifi",
"param": "param1-1",
"subMenu2": [
{
"type": "JVC",
"param": "param1-1-1"
},
{
"type": "Kennwood",
"param": "param1-1-2"
},
{
"type": "Sony",
"param": "param1-1-3"
},
{
"type": "Blaupunkt",
"param": "param1-1-4"
}
]
}]}]
I need to retrieve the length of the subarrays subMenu and subMenu2 for a specific function but have not found a suitable solution yet.
I have tried using a loop with
for (var i = 0; i < array.length; i++)
and for (var i = 0; i < subMenu.length; i++)
but it did not give me the correct lengths. It was limited by the length of the main array.
You can see the issue in action here: https://jsfiddle.net/pp4t9nw2/4/
If anyone has a solution to this problem, I would greatly appreciate it.