जावास्क्रिप्ट foreach
const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
console.log(index, item)
})
जावास्क्रिप्ट foreach
var colors = ['red', 'blue', 'green'];
colors.forEach(function(color) {
console.log(color);
});
प्रत्येक जेएस के लिए
const fruits = ['mango', 'papaya', 'pineapple', 'apple'];
// Iterate over fruits below
// Normal way
fruits.forEach(function(fruit){
console.log('I want to eat a ' + fruit)
});
जावास्क्रिप्ट foreach उदाहरण
var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
console.log(color);
});
जावास्क्रिप्ट foreach सूचकांक
users.forEach((user, index)=>{
console.log(index); // Prints the index at which the loop is currently at
});
सरणी में प्रत्येक आइटम के लिए जे एस
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
// expected output: "a"
// expected output: "b"
// expected output: "c"