- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Array forEach
JavaScript Arrays
JavaScript Array forEach
JavaScript
forEachruns a function once for every element in an array.
It is the method version of a for of loop.
It always returns undefined, so it is used for doing something rather than building a result.
Example
Example
javascript
const fruits = ["Apple", "Banana"];
fruits.forEach(function (fruit) {
console.log(fruit);
});Each name is printed on its own line.
