can we give foreach in a foreach loop in javascript code example
Example 1: foreach javascript
let words = ['one', 'two', 'three', 'four'];
words.forEach((word) => {
console.log(word);
});
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
listName.forEach((listItem) => {
Logger.log(listItem);
}):
Example 4: foreach javascript
Used to execute the same code on every element in an array
Does not change the array
Returns undefined