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 141 views
1 answer 103 views
1 answer 134 views
1 answer 123 views
1 answer 109 views
109 views asked Aug 13, 2022 by avibootz
1 answer 104 views
1 answer 131 views
...