
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
For Loops in Javascript
Let’s start with the for loop. There are 2 variations of the for loop in js. The first form is the init, condition, expr loop. This initializes the first statement, then on each iteration executes the expr and checks the condition.
Example
For example,
var step; for (step = 0; step < 5; step++) { console.log('Taking step ' + step); }
Output
This will give the output −
Taking step 0 Taking step 1 Taking step 2 Taking step 3 Taking step 4
There is another form of the for loop, the for in loop. The for...in statement iterates a specified variable over all the enumerable properties of an object. For each distinct property, JavaScript executes the specified statements. For example,
Example
let person = { name: "John", age: 35 }; for (let prop in person) { console.log(prop, a[prop]); }
Output
This will give the output −
name John age 35
- Related Articles
- Reverse array with for loops JavaScript
- What is the difference between for...in and for...of loops in JavaScript?
- For and While loops in Arduino
- Finding closed loops in a number - JavaScript
- Demonstrate nested loops with return statements in JavaScript?
- Array flattening using loops and recursion in JavaScript
- How to get sequence number in loops with JavaScript?
- Loops in Java
- What is basic syntax of Python for Loops?
- What are the best practices for using loops in Python?
- How to use multiple for and while loops together in Python?
- Loops in Dart Programming
- What is the best way to break from nested loops in JavaScript?
- How to iterate over dictionaries using 'for' loops in Python?
- Loops in C and C++

Advertisements