How to reverse the order of a map in Node.js

1 Answer

0 votes
let mp = new Map();
    
mp.set("NodeJS", 23);
mp.set("Java", 89);
mp.set("C", 31);
mp.set("C++", 93);
mp.set("PHP", 77);
 
mp = new Map(Array.from(mp).reverse());
 
mp.forEach((value, key) => {
    console.log(`${key} ${value}`);
});
    
        
    
        
         
/*
run:
         
PHP 77
C++ 93
C 31
Java 89
NodeJS 23
         
*/

 



answered May 17, 2022 by avibootz

Related questions

1 answer 107 views
2 answers 117 views
1 answer 136 views
1 answer 162 views
1 answer 144 views
1 answer 117 views
1 answer 85 views
...