how to get the values from an object in javascript code example
Example 1: javascript object get value by key
const person = {
name: 'Bob',
age: 47
}
Object.keys(person).forEach((key) => {
console.log(person[key]);
});
Example 2: object values
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.values(object1));
Example 3: get all entries in object as array hjs
const object1 = {
a: 'somestring',
b: 42
};
for (let [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 4: javascript object get value by key
var obj = {
a: "A",
b: "B",
c: "C"
}
console.log(obj.a);
var name = "a";
console.log(obj[name]);