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 133 views
1 answer 95 views
1 answer 128 views
1 answer 112 views
1 answer 104 views
104 views asked Aug 13, 2022 by avibootz
1 answer 96 views
1 answer 123 views
...