1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1For printing 0 to 9
2
3you can write like below also
4var i;
5for (i = 0; i < 10; i++) {
6 console.log(i);
7}
1Example:
2const object = { a: 1, b: 2, c: 3 };
3
4for (const property in object) {
5 console.log(`${property}: ${object[property]}`);
6}
7
8// expected output:
9// "a: 1"
10// "b: 2"
11// "c: 3"
12
13
14Syntax:
15for (variable in object)
16 statement
1var scores = [21, 35, 54, 46];
2 var arrayLength = scores.length;
3 var msg = '';
4 var i;
5
6 for (i = 0; i < arrayLength; i++) {
7 roundNumber = (i + 1);
8 msg += 'Round ' + roundNumber + ': ';
9 msg += scores[i] + '<br />';
10 }