Answers for "foreach js w3school"

8

loop array javascript

var colors = ['red', 'green', 'blue'];
	
	colors.forEach((color, colorIndex) => {
     console.log(colorIndex + ". " + color); 
    });
Posted by: Guest on April-08-2020
35

foreach javascript

let words = ['one', 'two', 'three', 'four'];
words.forEach((word) => {
  console.log(word);
});
// one
// two
// three
// four
Posted by: Guest on May-27-2020
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>";
}
Posted by: Guest on October-16-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language