I have a PHP function that returns a multiple-level JSON object in the format
var data = {
1 : {
1: { Object },
2: { Object },
...,
...
},
2: {
1: { Object },
2: { Object },
...,
...
}
}
I need to get the length of data
to initialize a for loop maximum value. By this, I mean the count of the first level entries.
data[1].length
returns 22, and data[2].length
returns 23 via the console.log
printout. This is expected, but data.length
returns undefined.
Is there a better method than
var count = 0;
for (var i=1; i< Number.MAX_VALUE; i++){
if (typeof data[i] != 'undefined')
count = i;
}