1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.values(object1));
8
9// expected output: Array ["somestring", 42, false]
1// Access all properties and values in a JS object:
2let valuesArray = Object.entries(MyObject);
3
4 for (let value of valuesArray) {
5 document.write(value + "<br>"); // value is the property,value pair
6 }
7/* Result: propName,value
8 propName,value
9 ...
10
11For clarity: */
12let person = {
13 name: "Piet",
14 age: 42
15};
16
17Object.keys(person) // = ["name", "age"]
18Object.values(person) // = ["Piet", 42]
19Object.entries(person) // = [ ["name","Piet"], ["age",42] ]
20
1const object1 = {
2 a: 'somestring',
3 b: 42
4};
5
6for (let [key, value] of Object.entries(object1)) {
7 console.log(`${key}: ${value}`);
8}
9
10// expected output:
11// "a: somestring"
12// "b: 42"
13// order is not guaranteed
1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.values(object1));