xxxxxxxxxx
obj={
name:"akash",
age:23
}
keysval=Object.keys(obj)
console.log(keysval)
xxxxxxxxxx
function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}
const map = {"first" : "1", "second" : "2"};
console.log(getKeyByValue(map,"2"));
xxxxxxxxxx
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
xxxxxxxxxx
var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj));
// will output ["a", "b", "c"]
xxxxxxxxxx
const myObject = {
key1: 'value1',
key2: 'value2',
key3: 'value3'
};
const keys = Object.keys(myObject);
console.log(keys); // Output: ["key1", "key2", "key3"]
xxxxxxxxxx
// Sample object
const obj = {
key1: "value1",
key2: "value2",
key3: "value3"
};
// Retrieve keys of the object using Object.keys method
const keys = Object.keys(obj);
// Print the keys
console.log(keys);
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 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);