1const object1 = {
2 a: 'somestring',
3 b: 42
4};
5
6for (const [key, value] of Object.entries(object1)) {
7 console.log(`${key}: ${value}`);
8}
1var lunch = {
2 sandwich: 'ham',
3 snack: 'chips',
4 drink: 'soda',
5 desert: 'cookie',
6 guests: 3,
7 alcohol: false,
8};
9
10Object.keys(lunch).forEach(function (item) {
11 console.log(item); // key
12 console.log(lunch[item]); // value
13});
14
15// returns "sandwich", "ham", "snack", "chips", "drink", "soda", "desert", "cookie", "guests", 3, "alcohol", false
16