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 128 views
1 answer 133 views
1 answer 105 views
1 answer 124 views
1 answer 121 views
1 answer 111 views
3 answers 162 views
...