forEach Es6 code example

Example 1: es6 forEach

const array1 = ['a', 'b', 'c'];

array1.forEach((element) => {
  console.log(element)
});

// expected output: "a"
// expected output: "b"
// expected output: "c"

Example 2: javascript foreach index

users.forEach((user, index)=>{
	console.log(index); // Prints the index at which the loop is currently at
});

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

//es6
Array.from(els).forEach((el) => {
});

//old shit
Array.prototype.forEach.call(els, function(el) {
    // Do stuff here
    console.log(el.tagName);
});

// Or
[].forEach.call(els, function (el) {...});