const myObj = {
firstName: 'John',
lastName: 'Duo',
address: '1270.0.0.1'
}
const keys = Object.keys(myObj); // firstName, lastName, address
const values = Object.values(myObj); // John, Duo, 127.0.0.1
myObject = {
"key": "value"
}
Object.keys(myObject); // get array of keys
var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj));
// will output ["a", "b", "c"]
obj={
name:"akash",
age:23
}
keysval=Object.keys(obj)
console.log(keysval)
const arr = ['name', 'age', 'country'];
const obj = arr.reduce((accumulator, value) => {
return {...accumulator, [value]: ''};
}, {});
console.log(obj); // {name: '', age: '', country: ''}
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property ); // Outputs: foo, fiz or fiz, foo
}
Object.keys(whateverYourObjectIsCalled)