1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
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!
1var colors = ["red","blue","green"];
2colors.forEach(function(color) {
3 console.log(color);
4});
1// Arrow function
2forEach((element) => { ... } )
3forEach((element, index) => { ... } )
4forEach((element, index, array) => { ... } )
5
6// Callback function
7forEach(callbackFn)
8forEach(callbackFn, thisArg)
9
10// Inline callback function
11forEach(function callbackFn(element) { ... })
12forEach(function callbackFn(element, index) { ... })
13forEach(function callbackFn(element, index, array){ ... })
14forEach(function callbackFn(element, index, array) { ... }, thisArg)