1let array = ['Item 1', 'Item 2', 'Item 3'];
2
3array.forEach(item => {
4 console.log(item); // Logs each 'Item #'
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
6
1 //Am goinmg to practice the next big thing, using for.each function yo tripple iontegers in an array :)
2 //for.each function is used to run a command on each number or string in an array
3 const theFigures = [2,4,5,6,7,8,9,12,23,45,68,31,90];
4 const afterMath = (num) => {
5 const theArray = [];
6 num.forEach((n) => {
7 const trippled = n*3;
8 theArray.push(trippled);
9 });
10 return theArray;
11 }
12 console.log(afterMath(theFigures));