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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

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

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

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

Booking.com | Official site | The best hotels, flights, car rentals & accommodations


131 views
asked Mar 24, 2020 by avibootz
edited Mar 24, 2020 by avibootz

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 92 views
2 answers 100 views
1 answer 92 views
...