get key value object javascript code example
Example 1: javascript object entries
const object1 = {
a: 'somestring',
b: 42
}
Object.entries(object1)
.forEach(([key, value]) => console.log(`${key}: ${value}`))
Example 2: for key value in object javascript
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 3: javascript object get value by key
const person = {
name: 'Bob',
age: 47
}
Object.keys(person).forEach((key) => {
console.log(person[key]);
});
Example 4: js object keys
var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);