How to create a map with object in Node.js

1 Answer

0 votes
const mp = new Map([
  ['str', 'nodejs'],
  ['obj', {id: 9837, country: 'canada'}],
]);
 

console.log([...mp.entries()]);
 
console.log([mp.get('obj')]); 

console.log([mp.get('obj').id]);    
console.log([mp.get('obj').country]);   




   
/*
run:
   
[ [ 'str', 'nodejs' ], [ 'obj', { id: 9837, country: 'canada' } ] ]
[ { id: 9837, country: 'canada' } ]
[ 9837 ]
[ 'canada' ]
   
*/

 



answered May 29, 2022 by avibootz

Related questions

1 answer 228 views
1 answer 187 views
1 answer 218 views
1 answer 201 views
1 answer 204 views
204 views asked Aug 13, 2022 by avibootz
1 answer 188 views
1 answer 218 views
...