for each nodejs code example
Example 1: javascript foreach index
users.forEach((user, index)=>{
console.log(index);
});
Example 2: js for each item do
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item);
});
Example 3: foreach javascript
let names = ['josh', 'joe', 'ben', 'dylan'];
names.forEach((name, index, sourceArr) => {
console.log(color, idx, sourceArr)
});
Example 4: boucle foreach js
let listeDePays = ['France', 'Belgique', 'Japon', 'Maroc'];
listeDePays.forEach(pays => console.log(pays));
Example 5: foreach javascript
Used to execute the same code on every element in an array
Does not change the array
Returns undefined