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});
1let numbers = ['one', 'two', 'three', 'four'];
2
3numbers.forEach((num) => {
4 console.log(num);
5}); // one //two //three // four
1const colors = ['blue', 'green', 'white'];
2
3function iterate(item) {
4 console.log(item);
5}
6
7colors.forEach(iterate);
8// logs "blue"
9// logs "green"
10// logs "white"
1arr.forEach(function callback(currentValue, index, array) {
2 // tu iterador
3}[, thisArg]);