1const avengers = ['thor', 'captain america', 'hulk'];
2avengers.forEach((item, index)=>{
3 console.log(index, item)
4})
1var colors = ['red', 'blue', 'green'];
2
3colors.forEach(function(color) {
4 console.log(color);
5});
1var stringArray = ["first", "second"];
2
3myArray.forEach((string, index) => {
4 var msg = "The string: " + string + " is in index of " + index;
5 console.log(msg);
6
7 // Output:
8 // The string: first is in index of 0
9 // The string: second is in index of 1
10});
1const arr = [0, 3, "hola", "hello", ";", true, [3, 6, 1]];
2arr.forEach((element, index) => {
3 console.log(element, index);
4});
5
6//output:
7
8// 0 0
9// 3 1
10// hola 2
11// hello 3
12// ; 4
13// true 5
14// [3, 6, 1] 6
1var colors = ["red", "blue", "green"];
2colors.forEach(function(color) {
3 console.log(color);
4});