javascript / beginner
Snippet
Iterating with Array.forEach()
The forEach() method executes a provided function once for each array element. Unlike map, it doesn't return a new array; it is used for side effects, like logging or updating an external variable during page rendering.
snippet.js
1
2
3
4
5
const pages = ["Home", "About", "Contact"];pages.forEach(function(page) {console.log("Loading page: " + page);});
nextjs
Breakdown
1
pages.forEach(function(page) {
Starts a loop that visits every item in the 'pages' array one by one.