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}
1var person={
2 first_name:"johnny",
3 last_name: "johnson",
4 phone:"703-3424-1111"
5};
6for (var property in person) {
7 console.log(property,":",person[property]);
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
1// For a functional one-liner
2Object.keys(pokemons).forEach(console.log);
3// Bulbasaur
4// Charmander
5// Squirtle
6// Pikachu