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});
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}
1let person={
2 first_name:"johnny",
3 last_name: "johnson",
4 phone:"703-3424-1111"
5};
6for (let i in person) {
7 let t = person[i]
8 console.log(i,":",t);
9}
1const object1 = {
2 a: 'somestring',
3 b: 42
4};
5for (let [key, value] of Object.entries(object1)) {
6 console.log(`${key}: ${value}`);
7}
8// expected output:
9// "a: somestring"
10// "b: 42"
11// order is not guaranteed
1const object = {a: 1, b: 2, c: 3};
2
3for (const property in object) {
4 console.log(`${property}: ${object[property]}`);
5}