The simplest approach to accomplish this while maintaining outstanding performance and compatibility with both old and modern browsers is to add Lo-Dash or Underscore in your website.
Then you may use _.size(object) or _.keys() (object).
length
You might try this with your obj.Data:
console.log( _.size(obj.Data) );
or:
console.log( _.keys(obj.Data).length );
Both Lo-Dash and Underscore are good libraries that you would find quite handy in your programming. (They are quite similar; Lo-Dash is a newer version with certain advantages.)
You may also include the following method in your code, which just runs over the object's properties and counts them:
function ObjectLength( object ) {
var length = 0;
for( var key in object ) {
if( object.hasOwnProperty(key) ) {
++length;
}
}
return length;
};
You can test this with:
console.log( ObjectLength(obj.Data) );
However, with newer browsers, such code is not as quick as it might be. You may use: for a version that is significantly quicker in newer browsers but still works in older ones.
function ObjectLength_Modern( object ) {
return Object.keys(object).length;
}
function ObjectLength_Legacy( object ) {
var length = 0;
for( var key in object ) {
if( object.hasOwnProperty(key) ) {
++length;
}
}
return length;
}
var ObjectLength =
Object.keys ? ObjectLength_Modern : ObjectLength_Legacy;
and as before, test it with:
console.log( ObjectLength(obj.Data) );
In contemporary browsers, this code utilises Object.keys(object).length; in older versions, it goes back to counting in a loop.
But if you're going to do all of this effort, I'd advocate utilising Lo-Dash or Underscore instead to reap the benefits of those libraries.