how to get object key value in javascript code example
Example 1: javascript iterate object key values
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
Example 2: get keys objet javascript
var foo = {
'alpha': 'puffin',
'beta': 'beagle'
};
var keys = Object.keys(foo);
console.log(keys)
Example 3: for key value in object javascript
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 4: js get object keys
myObject = {
"key": "value"
}
Object.keys(myObject);
Example 5: object keys javascript
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
Example 6: javascript object get value by key
const person = {
name: 'Bob',
age: 47
}
Object.keys(person).forEach((key) => {
console.log(person[key]);
});