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});
1const fruits = ['mango', 'papaya', 'pineapple', 'apple'];
2
3// Iterate over fruits below
4
5// Normal way
6fruits.forEach(function(fruit){
7 console.log('I want to eat a ' + fruit)
8});
1const array1 = ['a', 'b', 'c'];
2
3array1.forEach((element) => {
4 console.log(element)
5});
6
7// expected output: "a"
8// expected output: "b"
9// expected output: "c"
1let words = ['one', 'two', 'three', 'four'];
2words.forEach((word) => {
3 console.log(word);
4});
5// one
6// two
7// three
8// four
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