foreach in foreach code example
Example 1: javascript foreach example
var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
console.log(color);
});
Example 2: foreach in javascript
var a = ["a", "b", "c"];
a.forEach(function(entry) {
console.log(entry);
});
var fruits = ["apple", "orange", "cherry"];
fruits.forEach(myFunction);
function myFunction(item, index) {
document.getElementById("demo").innerHTML += index + ":" + item + "<br>";
}
Example 3: foreach loop javascript
const numList = [1, 2, 3];
numList.forEach((number) => {
console.log(number);
});
Example 4: foreach loop javascript
listName.forEach((listItem) => {
Logger.log(listItem);
}):
Example 5: what is foreach method in javascript
var arr = [1, 2, 3, 4, 5, 6];
arr.forEach(function (value, index, array){
console.log(value, index, array);
})