1var colors = ["red", "blue", "green"];
2colors.forEach(function(color) {
3 console.log(color);
4});
1var arr = [1, 2, 3, 4, 5, 6];
2
3//var sum = 0;
4arr.forEach(function (value, index, array){ // Built in method
5 //sum += value;
6 console.log(value, index, array);
7})
8
9//console.log(sum); // We can print sum of all Array element (if those are numbers)
10
11// function forEach(arr, cb){ // How forEach() method works
12// for (var i = 0; i<arr.length; i++){
13// cb(arr[i], i, arr);
14// }
15// }
16// var sum = 0;
17// forEach(arr, function (value, index, arr){
18// console.log(value, index, arr);
19// sum += value;
20// })
21// console.log(sum);