xxxxxxxxxx
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
xxxxxxxxxx
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
xxxxxxxxxx
const person = {
key: "value",
first_name: "John",
last_name: "Doe"
};
Object.keys(person);
Output: ['key', 'first_name', 'last_name']
xxxxxxxxxx
const object = {
name: "John",
age: 30,
gender: "male"
};
const keys = Object.keys(object);
console.log(keys);
xxxxxxxxxx
var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);//returnes the array ['no','my'];
xxxxxxxxxx
const obj = { a: 1, b: 2, c: 3 };
const keys = Object.keys(obj);
console.log(keys); // ["a", "b", "c"]
xxxxxxxxxx
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property ); // Outputs: foo, fiz or fiz, foo
}
xxxxxxxxxx
const obj = { name: 'John', age: 30, city: 'New York' };
const keys = Object.keys(obj);
console.log(keys);
xxxxxxxxxx
//Look at the other comments but heres a way I made it more simple
Object.prototype.keys=function(){return Object.keys(this);}
//you might see that im trying to make it short and comment use arrow functions.
//but arrow functions actually have diffrent abilites. see what happens.
const obj = {
foo:"bar",
bar:"foo"
}
console.log(obj.keys()); //["foo", "bar"]
Object.defineProperty(Object.prototype, "keys", { //more simpler to use
get:function(){return Object.keys(this);}
});
console.log(obj.keys); //["foo", "bar"]