Maps and Sets in javascript
Map:
To make a new Map, you can use the Map constructor:
new Map();
let bestBoxers = new Map();
bestBoxers.set(1, “The Champion”);bestBoxers.set(2, “The Runner-up”);
bestBoxers.set(3, “The third place”);
console.log(bestBoxers);
output:
Map(3) {1 => ‘The Champion’, 2 => ‘The Runner-up’, 3 => ‘The third place’}
Get Sirisha komma’s stories in your inbox
Join Medium for free to get updates from this writer.
to get a specific value
bestBoxers.get(1); // ‘The Champion’
Set:
A set is a collection of unique values.
To build a new set, you can use the Set constructor:
new Set();
const repetitiveFruits = [‘apple’,’pear’,’apple’,’pear’,’plum’, ‘apple’];
const uniqueFruits = new Set(repetitiveFruits);
console.log(uniqueFruits);
output:
{‘apple’, ‘pear’, ‘plum’}





