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 222 views
1 answer 230 views
1 answer 192 views
1 answer 233 views
1 answer 210 views
1 answer 219 views
219 views asked May 20, 2022 by avibootz
1 answer 199 views
...