1let obj = {
2 key1: "value1",
3 key2: "value2",
4 key3: "value3",
5 key4: "value4",
6}
7Object.entries(obj).forEach(([key, value]) => {
8 console.log(key, value);
9});
1'use strict';
2// ECMAScript 2017
3const object = {'a': 1, 'b': 2, 'c' : 3};
4for (const [key, value] of Object.entries(object)) {
5 console.log(key, value);
6}
1Object.entries(obj).forEach(([key, value]) => {
2 console.log(key, value);
3});
1const object = {a: 1, b: 2, c: 3};
2
3for (const property in object) {
4 console.log(`${property}: ${object[property]}`);
5}
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