const numList = [1, 2, 3];
numList.forEach((number) => {
console.log(number);
});
var array = ["a","b","c"];
// example 1
for(var value of array){
console.log(value);
value += 1;
}
// example 2
array.forEach((item, index)=>{
console.log(index, item)
})
const array = ['Element_1', 'Element_2', 'Element_3']
array.forEach((currentElement, currentElementIndex, arrayOfCurrentElement) => {
console.log(currentElement, currentElementIndex, arrayOfCurrentElement)
})
listName.forEach((listItem) => {
Logger.log(listItem);
}):
// 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' ]
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