access object values in javascript code example
Example 1: javascript access property values list of objects
let valuesArray = Object.entries(MyObject);
for (let value of valuesArray) {
document.write(value + "<br>");
}
let person = {
name: "Piet",
age: 42
};
Object.keys(person)
Object.values(person)
Object.entries(person)
Example 2: js objects
const dog = {
name: "Rusty",
breed: "unknown",
isAlive: false,
age: 7
}
dog.age;
dog["age"];
dog.breed = "mutt";
dog["age"] = 8;
Example 3: objects javascript
function Dog() {
this.name = "Bailey";
this.colour = "Golden";
this.breed = "Golden Retriever";
this.age = 8;
}