Answers for "how to add an array of numbers using forEach javascript"

56

javascript foreach

var colors = ['red', 'blue', 'green'];

colors.forEach(function(color) {
  console.log(color);
});
Posted by: Guest on June-27-2019
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
3

forEach index

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

array1.forEach((element, index) => console.log(element, index));
Posted by: Guest on September-09-2020

Code answers related to "how to add an array of numbers using forEach javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language