node.js hash, retrieve keys?


Just started with Node.JS, maybe this is more a javascript question but, its a thin line.

when i start-up node in CLI i do the following:

> x = {num:1, str:'hello', ar:[1,2,3], func:function calc(i){return i *2}}

now i can say:

> x.num
> x.str
>        // [1,2,3]
> // 3
>[0]     // 1
> x.calc(10)

thats pretty clear. But now i want know which keys x contains?

// this doesn't work 
x.keys   // undefined
x.length // undefined

So how do you retrieve the keys of this hash?

And my second question is, what object is x ? how can i get the name of this object?

Problem courtesy of: Roger


Try Object.keys(x); Here are the docs:

Solution courtesy of: rdrey


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.