Looping and interation in JavaScript

A loop is a programming construct that allows you to repeat a specific set of code multiple times. There are several different types of loops in JavaScript, but they essentially do the same thing: Repeat an action a certain amount of times. Here are some examples:

for loop

for (var i = 0; i < array.length; i++) { 
    console.log(array[i]);
} 

forEach

array.forEach(function(element) { 
    console.log(element); 
}); 

map()

array.map(function(element) { 
    console.log(element); 
}); 

filter()

array.filter(function(element) { 
    return element === 3; 
}); 

some()

array.some(function(element) { 
    return element === 3; 
}); 

every()

array.every(function(element) { 
    return element === 3; 
}); 

reduce()

array.reduce(function(accumulator, element) { 
    return accumulator + element; 
}, 0);

Feel free to reach out if you have any questions or comments.