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// 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]
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
1var data={"id" : 1, "second" : "abcd"};
2$.each(data, function() {
3 var key = Object.keys(this)[0];
4 var value = this[key];
5 //do something with value;
6});
7