node.js hash, retrieve keys?

Problem

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
> x.ar        // [1,2,3]
> x.ar.length // 3
> x.ar[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

Solution

Try Object.keys(x); Here are the docs: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys

Solution courtesy of: rdrey

Discussion

There is currently no discussion for this recipe.

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