Here is original question: Getting JavaScript object key list
But if the situation is little bit more complex like:
var obj = [
{ key1: 'value1' },
{ key2: 'value2' },
{ key3: 'value3' },
{ key4: 'value4' }
]
Then how you get keys like that?
[key1,key2,key3,key4]
You can use mix of Object.keys
and Array#flatMap
.
let obj = [
{ key1: 'value1' },
{ key2: 'value2' },
{ key3: 'value3' },
{ key4: 'value4' },
];
let keys = obj.flatMap(Object.keys);
console.log(keys);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With