1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
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
1let items = ['beef', 'cabbage', 'javascript']; // Defines a list of items
2for (let item of items) { // Defines for loop with a variable of 'item'
3 console.log(item); // Prints the item that is found
4}
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
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