for each loop with index code example
Example 1: for each
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
// expected output: "a"
// expected output: "b"
// expected output: "c"
Example 2: what foreach method returns in javascript
function double(arr) {
return arr.forEach(num => num*2);
}
console.log(double([1,2,3,4])) //undefined