1//for ... in statement
2
3const object = { a: 1, b: 2, c: 3 };
4
5for (const property in object) {
6 console.log(`${property}: ${object[property]}`);
7}
8
9// expected output:
10// "a: 1"
11// "b: 2"
12// "c: 3"
13
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
1var person = {"name":"taylor","age":31};
2for (property in person) {
3 console.log(property,person[property]);
4}
5//name taylor
6//age 31
1let array = [1,2,3,4,5,6,7,8,9,10];
2// our array that we will use the for loop on
3for (let i = 0; i < array.length; i++) {
4 // this loop will console log the element at array[i] starting at 0
5 // and will continue looping for i < array.length
6 console.log(array[i]);
7 // after each loop i will increase by 1
8}
9
10// this will console log
11// 1
12// 2
13// 3
14// 4
15// 5
16// 6
17// 7
18// 8
19// 9
20// 10
21
1const object = { a: 1, b: 2, c: 3 };
2
3for (const property in object) {
4 console.log(`${property}: ${object[property]}`);
5}
6
7// expected output:
8// "a: 1"
9// "b: 2"
10// "c: 3"
11