Example 1: es6 forEach
const array1 = ['a', 'b', 'c'];
array1.forEach((element) => {
console.log(element)
});
Example 2: foreach jas
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 3: for each javascript
let numbers = ['one', 'two', 'three', 'four'];
numbers.forEach((num) => {
console.log(num);
});
Example 4: for each javascript
const movies = [
{name: "A New Hope", director: "George Lucas", release: "1977-05-25", episodeID: 4},
{name: "Attack of the Clones", director: "George Lucas", release: "2002-05-16", episodeID: 2},
{name: "Return of the Jedi", director: "Richard Marquand", release: "1983-05-25", episodeID: 6},
{name: "Revenge of the Sith", director: "George Lucas", release: "2005-05-19", episodeID: 3},
{name: "The Empire Strikes Back", director: "Irvin Kershner", release: "1980-05-17", episodeID: 5},
{name: "The Phantom Menace", director: "George Lucas", release: "1999-05-19", episodeID: 1}
]
movies.forEach((movies) => {
console.log(movies.name);
});
Example 5: boucle foreach js
let listeDePays = ['France', 'Belgique', 'Japon', 'Maroc'];
listeDePays.forEach(pays => console.log(pays));
Example 6: javascript foreach
const colors = ['blue', 'green', 'white'];
function iterate(item) {
console.log(item);
}
colors.forEach(iterate);