0 day streak
javascript / beginner
Snippet

Iterating with forEach

The forEach method is a clean way to loop through every item in an array and perform an action for each element.

snippet.js
javascript
1
2
3
4
const fruits = ['Apple', 'Banana', 'Orange'];
fruits.forEach((fruit) => {
console.log(`I love ${fruit}s`);
});
nodejs
Breakdown
1
fruits.forEach((fruit) => {
Calls a function for every element in the 'fruits' array.