javascript each funciton code example
Example 1: how to use the foreach method in javascript
groceries.forEach(groceryItem => console.log(groceryItem));
Example 2: javascript foreach
const colors = ['blue', 'green', 'white'];
function iterate(item) {
console.log(item);
}
colors.forEach(iterate);
// logs "blue"
// logs "green"
// logs "white"
Example 3: javascript foreach syntax
const marks = [12, 17, 14];
let sum = 0;
marks.forEach(mark => {
sum += mark;
});