javascript foreach
const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
console.log(index, item)
})
connect.sonveer
const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
console.log(index, item)
})
users.forEach((user, index)=>{
console.log(index); // Prints the index at which the loop is currently at
});
const iterable = [...];
for (const [index, elem] in iterable.entries()) {
f(index, elem);
}
// or
iterable.forEach((elem, index) => {
f(index, elem);
});
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
let numbers = ['one', 'two', 'three', 'four'];
numbers.forEach((num) => {
console.log(num);
}); // one //two //three // four
var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
console.log(color);
});