How can I find the keys of an object?

I know in JavaScript, objects double as hashes, but I have been unable to find a built-in function to get the keys:

var h = {a:'b', c:'d'};

I want something like

var k = h.keys() ; // k = ['a', 'c'];

It is simple to write a function myself to iterate over the items and add the keys to an array that I return, but is there a standard cleaner way to do that?

I keep feeling it must be a simple built in function that I missed but I can’t find it!

9 Answers
9

Leave a Comment