-1

I have an Object. How to get number of nested objects in a?

a = {
    firstNested: {
        name: 'George'
    }
    secondNested: {
        name: 'James'
    }
}

I supposed to use .length which is usually used for arrays. What should I do in this case?

Vlad Holubiev
  • 4,876
  • 7
  • 44
  • 59

1 Answers1

1

Yes, duplicate of above.. Just use:

var a = {1:2, 3:4}, 
    count = 0, 
    item; 

for(item in a) {
    count++; 
}

alert(count);
Vladimir Georgiev
  • 1,949
  • 23
  • 26