Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 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, 2020 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, 2020 by avibootz

Related questions

2 answers 176 views
1 answer 148 views
1 answer 135 views
2 answers 157 views
3 answers 187 views
...