Answers for "foreach js example"

131

javascript foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
Posted by: Guest on April-27-2020
20

javascript foreach example

var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
    console.log(color);
});
Posted by: Guest on July-19-2019
6

foreach loop javascript

const numList = [1, 2, 3];

numList.forEach((number) => {
  console.log(number);
});
Posted by: Guest on October-05-2020
9

javascript .foreach

let colors = ['red', 'blue', 'green'];
// idx and sourceArr optional; sourceArr == colors
colors.forEach(function(color, idx, sourceArr) {
	console.log(color, idx, sourceArr)
});
// Output:
// red 0 ['red', 'blue', 'green']
// blue 1 ['red', 'blue', 'green']
// green 2 ['red', 'blue', 'green']
Posted by: Guest on April-07-2020
0

JavaScript Array Methods .forEach()

let days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
days.forEach(function log(day) {
  console.log(day)
})

// ES6 verzió óta lehetséges az ún. "array function" használata
// az eredmény ugyanaz lesz, mint az előző szintaxissal
days.forEach(day => {
  console.log(day)
});

// amikor a függvénytörzs egy sor, kapcsos zárójel és sortörés nélkül is
// írhatjuk a függvényt
days.forEach(day => console.log(day));
Posted by: Guest on May-07-2021
0

foreach javascript

let colors = ['red', 'blue', 'green'];
// idx and sourceArr optional; sourceArr == colors
colors.forEach(function(color, idx, sourceArr) {
	console.log(color, idx, sourceArr)
});
Posted by: Guest on June-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language