const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach(element => {
//Statement
console.log(element);
});
const array = ['Element_1', 'Element_2', 'Element_3']
array.forEach((currentElement, currentElementIndex, arrayOfCurrentElement) => {
console.log(currentElement, currentElementIndex, arrayOfCurrentElement)
})
// Durations are in minutes
const tasks = [
{
'name' : 'Write for Envato Tuts+',
'duration' : 120
},
{
'name' : 'Work out',
'duration' : 60
},
{
'name' : 'Procrastinate on Duolingo',
'duration' : 240
}
];
const task_names = [];
tasks.forEach(function (task) {
task_names.push(task.name);
});
console.log(task_names) // [ 'Write for Envato Tuts+', 'Work out', 'Procrastinate on Duolingo' ]
array.forEach(function calback(item, index, array)
{
/* working codes here */
});
const names = ['Anthony','Stacey','Mason','Gracie','Koda','Nani'];
forEach(function(name) {
console.log(name);
});
const scores = [22, 54, 76, 92, 43, 33];
scores.forEach((score) => {
console.log(score);
});
// You can write the above in one line this way:
// scores.forEach((score) => console.log(score));
// will return
// 22
// 54
// 76
// 92
// 43
// 33