How to convert a map to an object in Node.js

1 Answer

0 votes
const mp = new Map();
  
mp.set('c', 1);
mp.set('c++', 2);
mp.set('php', 3);
mp.set('java', 4);
mp.set('nodejs', 5);

const obj = Object.fromEntries(mp);

console.log(obj); 
  
  
  
  
/*
run:

{ c: 1, 'c++': 2, php: 3, java: 4, nodejs: 5 }
  
*/

 



answered May 20, 2022 by avibootz

Related questions

1 answer 220 views
1 answer 228 views
1 answer 190 views
1 answer 231 views
1 answer 208 views
1 answer 216 views
216 views asked May 20, 2022 by avibootz
1 answer 199 views
...