javascript for each in list code example
Example 1: for each js
const fruits = ['mango', 'papaya', 'pineapple', 'apple'];
fruits.forEach(function(fruit){
console.log('I want to eat a ' + fruit)
});
Example 2: js for each item in array
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 3: boucle foreach js
let listeDePays = ['France', 'Belgique', 'Japon', 'Maroc'];
listeDePays.forEach(pays => console.log(pays));
Example 4: javascript foreach call specific value in array
run.addEventListener("click", function () {
people.forEach((element) => console.log(element.firstname));
});