1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1let str = "";
2
3for (let i = 0; i < 9; i++) {
4 str = str + i;
5}
6
7console.log(str);
8// expected output: "012345678"
9
1const object = {a: 1, b: 2, c: 3};
2
3for (const property in object) {
4 console.log(`${property}: ${object[property]}`);
5}
1var obj = {a: 1, b: 2, c: 3};
2
3for (const prop in obj) {
4 console.log(`obj.${prop} = ${obj[prop]}`);
5}
6
7// Output:
8// "obj.a = 1"
9// "obj.b = 2"
10// "obj.c = 3"
11
1
2const person = {fname:"John", lname:"Doe", age:25};
3
4
5let text = "";
6for (let x in person) {
7
8 text += person[x];
9
10}
1const p = {
2 "p1": "value1",
3 "p2": "value2",
4 "p3": "value3"
5};
6
7for (let [key, value] of Object.entries(p)) {
8 console.log(`${key}: ${value}`);
9}