DEV Community

Syed Faysel Ahammad Rajo
Syed Faysel Ahammad Rajo

Posted on

All types of loop in JavaScript

For Loop

While loop

Do while loop

Apart from this three traditional loop, there two shortcut loop in newer javaScript.

Useful shortcut loop (for of, for in)

For of loop

To loop over an array we can use the for of loop.

let nums = [2,3,4,5,6,7];
for (const num of nums){
   console.log(num);
}
Enter fullscreen mode Exit fullscreen mode

For in loop

To loop over an object, we can use for in loop

let info = {
    name : "rajo",
    id : 124,
    isAlve : true
};
for (const key in info){
   console.log(info[key]);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)