0

I have a following object:

var sample =
{
    count: {
        '20-01-2015/17': {
            'a': 553056,
            'b': 622123
        },
        '20-01-2015/18': {
            'a': 519008,
            'b': 610474
        }
    }
}

I want to find all the keys for count property. Also, all the keys for 20-01-2015/17 property also.

var times = Object.keys(sample.count);
console.log(times);
var time = '20-01-2015/17'

//This works
var props = Object.keys(sample.count[time]);
console.log(props);

//But this doesn't work. I am not able to understand that.
props = Object.keys(sample.count.time);
console(props)

I didn't understand why the first approach is working, but not the second one.

Prachi g
  • 849
  • 3
  • 9
  • 23
  • 1
    the last one try to access a property `time` on the object `count`, (not the value of time as the property name) – Hacketo Jan 24 '15 at 10:40

1 Answers1

0

Object.keys() is used to ENUMERATE all properties that have their Enumerable flag turned on in the object descriptor including functions, for example, if you do this Objects.keys(Array.prototype) it will print all the functions defined on the prototype property of the Array which is shared by all Array objects.

Trash Can
  • 6,608
  • 5
  • 24
  • 38