1myObject ={a:1,b:2,c:3}
2
3//es6
4Object.entries(myObject).forEach(([key, value]) => {
5 console.log(key , value); // key ,value
6});
7
8//es7
9Object.keys(myObject).forEach(key => {
10 console.log(key , myObject[key]) // key , value
11})
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
14