Reputation: 20790
Supposing I have such object:
var obj = {
'a': 'fizzle',
'b': 'wizzle',
'c': 'bum',
'd': 'crum'
}
I would like to take the key names and flatten these into an array, like so:
// -> ['a', 'b', 'c', 'd'];
I could achieve this with a simple object loop, however I am wondering if there is a common underscore
utility that could turn it into a one-liner. I looked through the underscore
functions and couldn't find one for this.
Upvotes: 2
Views: 696
Reputation: 55750
You could just use Object.keys()
method available on the native Object constructor
, Which outputs the original objects own enumerable properties.
Object.keys(obj);
Upvotes: 2