array forEacg javascript code example
Example 1: foreach javascript
var items = ["item1", "item2", "item3"]
var copie = [];
items.forEach(function(item){
copie.push(item);
});
Example 2: foreach in javascript
///Simple One
var a = ["a", "b", "c"];
a.forEach(function(entry) {
console.log(entry);
});
///Function concept
var fruits = ["apple", "orange", "cherry"];
fruits.forEach(myFunction);
function myFunction(item, index) {
document.getElementById("demo").innerHTML += index + ":" + item + "<br>";
}