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
var obj = { first: 'someVal', second: 'otherVal' };
alert(Object.keys(obj)[0]); // returns 'first'
alert(Object.keys(obj)[1]); // returns 'second'
xxxxxxxxxx
var obj = { "a" : 1, "b" : 2, "c" : 3};
alert(Object.keys(obj));
// will output ["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 myObject = {
key1: 'value1',
key2: 'value2',
key3: 'value3'
};
const keys = Object.keys(myObject);
console.log(keys); // Output: ["key1", "key2", "key3"]
xxxxxxxxxx
const object = {
name: "John",
age: 30,
gender: "male"
};
const keys = Object.keys(object);
console.log(keys);
xxxxxxxxxx
obj={
name:"akash",
age:23
}
keysval=Object.keys(obj)
console.log(keysval)
xxxxxxxxxx
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property ); // Outputs: foo, fiz or fiz, foo
}
xxxxxxxxxx
getKeyByValue(obj: any, searchValue: string[]) {
for (const [key, value] of obj.entries()) {
if (value === searchValue) return key;
}
}