What are the iterable statement in JS?

0 votes
29 views
Ravi Vishwakarma asked 13 days ago in Web Application by Ravi Vishwakarma

What are the iterable statement in JS?

1 Answer

0 votes
Ethan Karla answered 12 days ago by Ethan Karla
The JavaScript loops are used to iterate the piece of code using for, while, do while or for-in loops. It makes the code compact. It is mostly used in array. There are four types of loops in JavaScript.
1. for loop
2. while loop
3. do-while loop
4. for-in loop
For loop
 for (declaration ; condition ; updation [increment or decrement]){

  True statement ……
 } another statement
Example:
 for (var i = 0; i < 20; i++) {

   console.log('i = '+i);
 }
While loop
 declaration

 while(condition){
  true statement;
 updation
 }
Example:
 var i=5;

 while(i<60){
   console.log(i+' ');
   i=i+5;
 }
do-while
 declaration

 do{
  true statement;
 updation
 } while(condition);
Example:
var i=5;

do{
  console.log(i+' ');
  i=i+5;
}while(i<60);
For-in loop
 The JavaScript for in statement loops through the properties of an Object.
 for (key in object) {

   code block to be executed
 }
Example:
const person = {fname:'shivam', lname:'prajapati', age:45}; 

let txt = '';
for (let x in person) {
  txt += person[x] + ' ';
}
console.log(txt);