1let obj = {
2 key1: "value1",
3 key2: "value2",
4 key3: "value3"
5}
6
7Object.keys(obj).forEach(key => {
8 console.log(key, obj[key]);
9});
10// key1 value1
11// key2 value2
12// key3 value3
13
14// using for in - same output as above
15for (let key in obj) {
16 let value = obj[key];
17 console.log(key, value);
18}
1// iterates over all enumerable properties of an object that are
2// keyed by strings (ignoring ones keyed by Symbols),
3// including inherited enumerable properties.
4
5const object = { a: 1, b: 2, c: 3 };
6
7for (const property in object) {
8 console.log(`${property}: ${object[property]}`);
9}
10
11// expected output:
12// "a: 1"
13// "b: 2"
14// "c: 3"
1const obj = { a: 1, b: 2 };
2
3Object.keys(obj).forEach(key => {
4 console.log("key: ", key);
5 console.log("Value: ", obj[key]);
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}
1for (const [key, value] of Object.entries(object1)) {
2 console.log(`${key}: ${value}`);
3}
4
1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.keys(object1));
8// expected output: Array ["a", "b", "c"]