1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
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}
1var i; //defines i
2for (i = 0; i < 5; i++) { //starts loop
3 console.log("The Number Is: " + i); //What ever you want
4}; //ends loop
5//Or:
6console.log("The Number Is: " + 0);
7console.log("The Number Is: " + 1);
8console.log("The Number Is: " + 2);
9console.log("The Number Is: " + 3);
10console.log("The Number Is: " + 4);
11//They do the same thing!
12//Hope I helped!
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
1const obj = { a: 1, b: 2 };
2
3Object.keys(obj).forEach(key => {
4 console.log("key: ", key);
5 console.log("Value: ", obj[key]);
6} );