how to get object values in javascript code example
Example 1: how read values of object in javascript
var data={"id" : 1, "second" : "abcd"};
$.each(data, function() {
var key = Object.keys(this)[0];
var value = this[key];
});
Example 2: object values
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.values(object1));
Example 3: 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 4: javascript get values from object
Object.values(data)
Example 5: 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 6: 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]);