Loops in  JavaScript

Loops in JavaScript

for loop

This type of loop is used to iterate over a sequence of numbers. It is typically used to iterate over an array or an object.

while loop

A while loop in JavaScript is used to execute a block of code repeatedly as long as a specified condition is true.

do...while

A do...while loop in JavaScript is similar to a while loop, but the code inside the loop is executed at least once, regardless of whether the condition is true or false.

for...in

A for...in loop in JavaScript is used to iterate over the properties of an object.

for...of

A for...of loop in JavaScript is used to iterate over the values of an iterable, such as an array or a string.

forEach ( )

This method is used to execute a provided function once for each array element and it can only be used in an array.

map ( )

The map() method in JavaScript creates a new array with the results of calling a provided function on every element in the calling array.

filter ( )

This method creates a new array with all elements that pass the test implemented by the provided function.

reduce ( )

This method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.