1const avengers = ['thor', 'captain america', 'hulk'];
2avengers.forEach((item, index)=>{
3 console.log(index, item)
4})
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});
1users.forEach((user, index)=>{
2 console.log(index); // Prints the index at which the loop is currently at
3});
1const array1 = ['a', 'b', 'c'];
2
3array1.forEach(element => console.log(element));