“Foreach Method of Array in JavaScript” Réponses codées

javascript foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
connect.sonveer

javascript foreach

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

colors.forEach(function(color) {
  console.log(color);
});
Grepper

javascript foreach

fruits.forEach(function(item, index, array) {
  console.log(item, index)
})
// Apple 0
// Banana 1
Jittery Jay

foreach javascript

const fruits = ['mango', 'papaya', 'pineapple', 'apple'];

fruits.forEach(function(fruit){
  console.log('I want to eat a ' + fruit)
});
The Code Slayer

Foreach Method of Array in JavaScript

// foreach method of array in javascript
let numberArray = [1,2,3,4,5];
function printArrayValue(value, index){
    console.log(`value: ${value} = index: ${index}`);
}
numberArray.forEach(printArrayValue);
// Output:
// value: 1 = index: 0
// value: 2 = index: 1
// value: 3 = index: 2
// value: 4 = index: 3
// value: 5 = index: 4
Chetan Nada

Réponses similaires à “Foreach Method of Array in JavaScript”

Questions similaires à “Foreach Method of Array in JavaScript”

Plus de réponses similaires à “Foreach Method of Array in JavaScript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code