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 iterate over map in JavaScript

Freaking Awesome WordPress Hosting
796 views
asked Oct 30, 2021 by avibootz
edited Feb 23, 2022 by avibootz

3 Answers

0 votes
let mp = new Map();
  
mp.set("JavaScript", 23);
mp.set("Java", 89);
mp.set("C", 31);
mp.set("C++", 93);
mp.set("PHP", 77);
 
for (let entry of mp.entries()) {
    console.log(entry[0], entry[1]);    
}
  
  
       
       
/*
run:
       
"JavaScript", 23
"Java", 89
"C", 31
"C++", 93
"PHP", 77
       
*/

 





answered Oct 30, 2021 by avibootz
edited Jan 20, 2022 by avibootz
0 votes
let mp = new Map();
  
mp.set("JavaScript", 23);
mp.set("Java", 89);
mp.set("C", 31);
mp.set("C++", 93);
mp.set("PHP", 77);
 
for (let [key, value] of mp) {
    console.log(key, value);            
}
  
  
       
       
/*
run:
       
"JavaScript", 23
"Java", 89
"C", 31
"C++", 93
"PHP", 77
       
*/

 





answered Oct 30, 2021 by avibootz
edited Jan 20, 2022 by avibootz
0 votes
const mp = new Map([["typescript", 5], ["javascript", 4], ["nodejs", 9], ["c++", 2]])

mp.forEach((value, key) => {
    console.log(key, value);
});

 
 
 
   
/*
run:
        
"typescript", 5
"javascript", 4
"nodejs", 9
"c++", 2
           
*/
 

 





answered Aug 13, 2022 by avibootz
edited Aug 13, 2022 by avibootz

Related questions

1 answer 46 views
2 answers 75 views
1 answer 51 views
1 answer 70 views
...