#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Control Flow

Mastering Loops in JavaScript: A Comprehensive Guide

Why Loops Matter

Loops let you repeat a block of code without duplicating it, which is essential for working with arrays, objects, and repetitive tasks.

Overview of Loop Types

  • for loop — ideal when the number of iterations is known in advance.
  • while loop — repeats while a condition remains true, checked before each pass.
  • do...while loop — guarantees the body runs at least once before checking the condition.
  • for...in loop — iterates over the enumerable keys of an object.
  • for...of loop — iterates over the values of an iterable like an array, string, or Map.
let obj = { a: 1, b: 2 };
for (let key in obj) {
    console.log(key, obj[key]);
}

let arr = [1, 2, 3];
for (let val of arr) {
    console.log(val);
}

Choosing the Right Loop

Use for...of for array values, for...in for object keys, and classic for/while loops when you need full control over the iteration logic.

Ready to master real-world JavaScript development?

Learn JavaScript hands-on with mentor-led, live sessions.

Explore Course