foreach javascript dom code example
Example 1: javascript foreach
const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
console.log(index, item)
})
Example 2: foreach javascript
let words = ['one', 'two', 'three', 'four'];
words.forEach((word) => {
console.log(word);
});
Example 3: foreach in javascript
const avengers = ['IronMan','thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
console.log(index, item)
})
Example 4: 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);
})