1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.values(object1));
8// expected output: Array ["somestring", 42, false]
1//Supposing fooObj to be an object
2
3fooArray = Object.entries(fooObj);
4
5fooArray.forEach(([key, value]) => {
6 console.log(key); // 'one'
7 console.log(value); // 1
8})
9
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 c: false
5};
6
7console.log(Object.values(object1));
8
9// expected output: Array ["somestring", 42, false]