How to get the sum of all values in a map with Node.js

1 Answer

0 votes
const mp = new Map([
  ['javascript', 2],
  ['nodejs', 9],
  ['typescript', 7],
  ['python', 5],
]);
  
let sum = 0;

mp.forEach(value => {
  	sum += value;
});

console.log(sum); 
     
     
     
     
/*
run:
     
23
     
*/

 



answered May 27, 2022 by avibootz

Related questions

1 answer 158 views
2 answers 121 views
1 answer 221 views
2 answers 146 views
1 answer 136 views
1 answer 144 views
144 views asked May 1, 2023 by avibootz
...