forEach Es6 code example
Example 1: es6 forEach
const array1 = ['a', 'b', 'c'];
array1.forEach((element) => {
console.log(element)
});
Example 2: javascript foreach index
users.forEach((user, index)=>{
console.log(index);
});
Example 3: foreach javascript
var items = ["item1", "item2", "item3"]
var copie = [];
items.forEach(function(item){
copie.push(item);
});
Example 4: foreach jas
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 5: foreach javascript
Used to execute the same code on every element in an array
Does not change the array
Returns undefined
Example 6: es6 foreach dom element
Array.from(els).forEach((el) => {
});
Array.prototype.forEach.call(els, function(el) {
console.log(el.tagName);
});
[].forEach.call(els, function (el) {...});