for each in node js code example
Example 1: javascript .foreach
let colors = ['red', 'blue', 'green'];
colors.forEach(function(color, idx, sourceArr) {
console.log(color, idx, sourceArr)
});
Example 2: foreach javascript
let names = ['josh', 'joe', 'ben', 'dylan'];
names.forEach((name, index, sourceArr) => {
console.log(color, idx, sourceArr)
});
Example 3: for each
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 4: what foreach method returns in javascript
function double(arr) {
return arr.forEach(num => num*2);
}
console.log(double([1,2,3,4]))