Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,759 questions

17,366 answers

573 users

How to use the three types of for loops in JavaScript ES6

2 Answers

0 votes
function for_examples() { 
    var obj = {1:"abc", 2:"xyz", 3:"uvw", 4:"rst"}; 
  
    for(let i = 0 ; i <= 5; i++) { 
        console.log(i) 
    } 
    
    console.log('\n') 
    for (const e of ['node.js', "javascript", 123, 3.14]) { 
        console.log(e)  
    } 
    
    console.log('\n') 
    for (const key in obj) { 
        if (obj.hasOwnProperty(key)) {           
            console.log(key, obj[key]);
        }
    } 
} 

for_examples(); 

 
 
 
      
/*
run:
    
0
1
2
3
4
5


node.js
javascript
123
3.14


1 abc
2 xyz
3 uvw
4 rst
  
*/

 




answered Mar 24 by avibootz
0 votes
function for_examples() { 
    var obj = {1:"abc", 2:"xyz", 3:"uvw", 4:"rst"}; 
   
    for(let i = 0 ; i <= 6; i++) { 
        console.log(i) 
        if (i == 4) {
            break;
        }
    } 
     
    console.log('\n') 
    for (const e of ['node.js', "javascript", 123, 3.14]) { 
        if (e == 123) {
            continue;
        }
        console.log(e)  
    } 
     
    console.log('\n') 
    for (const key in obj) { 
        if (key == 3) {
            return;
        }
        if (obj.hasOwnProperty(key)) {           
            console.log(key, obj[key]);
        }
    } 
} 
 
for_examples(); 
  
  
  
       
/*
run:
     
0
1
2
3
4


node.js
javascript
3.14


1 abc
2 xyz
   
*/

 




answered Mar 24 by avibootz
...