const fruits = ['mango', 'papaya', 'pineapple', 'apple'];
// Iterate over fruits below
// Normal way
fruits.forEach(function(fruit){
console.log('I want to eat a ' + fruit)
});
let numbers = ['one', 'two', 'three', 'four'];
numbers.forEach((num) => {
console.log(num);
}); // one //two //three // four
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
// expected output: "a"
// expected output: "b"
// expected output: "c"
// array for the forEach method
let grades = [13, 12, 14, 15]
// for each loop
grades.forEach(function(grade) {
console.log(grade) // loops and logs every grade of the grades array
})
String[] fruits = {"apples", "oranges", "pears", "plums"}
for (String i:fruits)
{
System.out.print(i);
}